Ruby and JS quirks

1,908 views

Published on

A small presentation on quirky things in ruby and javascript. The presentation is heavily inspired by the talk from Gary Bernhardt

Published in: Technology
1 Comment
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total views
1,908
On SlideShare
0
From Embeds
0
Number of Embeds
1,054
Actions
Shares
0
Downloads
4
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Ruby and JS quirks

    1. 1. Ruby & Javascript Quirks Suman Mukherjee
    2. 2. Inspiration for the talkGary Bernhardt’s talk @ CodeMash 2012 https://www.destroyallsoftware.com/talks/wat
    3. 3. Ruby Javascript> var_1 = var_2 > var1 = var2# NameError: undefined local variable # ReferenceError: var2 is not definedor method var2 > var1> var_1 ReferenceError: var1 is not defined# nil
    4. 4. Ruby Javascript> “John” + {} > “John” + {}# TypeError: cant convert Hash into # John[object Object]String
    5. 5. Ruby Javascript> var_3 = var_3 > var3 = var3 # ReferenceError: var3 is not defined# nil
    6. 6. Ruby Javascript> [1, 2] + [3, 4] > [1, 2] + [3, 4] # 1,23,4# [1, 2, 3, 4]
    7. 7. Ruby Javascript> {} + [] Node# NoMethodError: undefined method `+ for {}:Hash > {} + [] # [object Object] Chrome console > {} + [] #0
    8. 8. Ruby Javascript> [] + {} > [] + {}# TypeError: cant convert Hash into # [object Object]Array
    9. 9. Ruby Javascript> [] + [] > [] + [] # ‘’# []
    10. 10. Ruby Javascript> {} + {} Node# NoMethodError: undefined method `+ for {}:Hash > {} + {} # [object Object][object Object] Chrome console > {} + {} # NaN
    11. 11. Ruby Javascript> “blah” + 3 > “blah” + 3# TypeError: cant convert Fixnum into # “blah3”String
    12. 12. Ruby Javascript> “blah” - 3 > “blah” - 3# NoMethodError: undefined method # NaN`- for "blah":String
    13. 13. Ruby Javascript> “blah” * 3 > “blah” * 3 # NaN# "blahblahblah"
    14. 14. JavascriptRuby > parseInt(undefined)> nil.to_i # NaN#0 > parseInt(null) # NaN> “”.to_i > parseInt(“”)#0 # NaN > undefined.toString() # TypeError: Cannot call method> nil.to_s toString of undefined# “” > null.toString() # TypeError: Cannot call method> 10.to_s toString of null# “10” > 10.toString() # SyntaxError > (10).toString() # ’10’
    15. 15. Ruby Javascript> 0/0 > 0/0# ZeroDivisionError: divided by 0 # NaN> 0.0/0 > 0.0/0# NaN # NaN
    16. 16. Ruby Javascript> “NaN”.to_f > parseFloat(“NaN”)# 0.0 # NaN
    17. 17. Ruby Javascript> “” == false > “” == false # true# false> [] == false > [] == false # true# false> 0 == false > 0 == false # true# false
    18. 18. Ruby Javascript> 0 && [] > 0 && []# [] #0> [] && 0 > [] && 0#0 #0> 0 && “” > 0 && “”# “” #0> “” && 0 > “” && 0#0 # “”> [] && “” > [] && “”# “” # “”> “” && [] > “” && []# [] # “”
    19. 19. Ruby Javascript> 5 == ‘5’ > 5 == ‘5’ # true# false
    20. 20. Ruby Javascript> {“grrrhhh”} > {“grrrhhh”} # grrrhhh# SyntaxError: compile error
    21. 21. Ruby Javascript> “a”===String.new(“a”) > “a”===new String(“a”) # false# true
    22. 22. Thank YouFollow me @mukherjeesuman

    ×