SlideShare a Scribd company logo
1 of 22
Ruby & Javascript
     Quirks

    Suman Mukherjee
Inspiration for the talk



Gary Bernhardt’s talk @ CodeMash 2012


     https://www.destroyallsoftware.com/talks/wat
Ruby                                   Javascript

> var_1 = var_2                        > var1 = var2
# NameError: undefined local variable   # ReferenceError: var2 is not defined
or method var2

                                       > var1
> var_1                                ReferenceError: var1 is not defined
# nil
Ruby                                   Javascript

> “John” + {}                          > “John” + {}
# TypeError: can't convert Hash into   # 'John[object Object]'
String
Ruby              Javascript

> var_3 = var_3   > var3 = var3
                  # ReferenceError: var3 is not defined
# nil
Ruby                Javascript

> [1, 2] + [3, 4]   > [1, 2] + [3, 4]
                    # '1,23,4'
# [1, 2, 3, 4]
Ruby                                 Javascript

> {} + []                            Node
# NoMethodError: undefined method `
+' for {}:Hash
                                     > {} + []
                                     # '[object Object]'


                                     Chrome console
                                     > {} + []
                                     #0
Ruby                                   Javascript

> [] + {}                              > [] + {}
# TypeError: can't convert Hash into   # '[object Object]'
Array
Ruby        Javascript

> [] + []   > [] + []
            # ‘’
# []
Ruby                                 Javascript

> {} + {}                            Node
# NoMethodError: undefined method `
+' for {}:Hash
                                     > {} + {}
                                     # '[object Object][object Object]'


                                     Chrome console
                                     > {} + {}
                                     # NaN
Ruby                                     Javascript

> “blah” + 3                             > “blah” + 3
# TypeError: can't convert Fixnum into   # “blah3”
String
Ruby                               Javascript

> “blah” - 3                       > “blah” - 3
# NoMethodError: undefined method   # NaN
`-' for "blah":String
Ruby               Javascript

> “blah” * 3       > “blah” * 3
                   # NaN
# "blahblahblah"
Javascript
Ruby
             > 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’
Ruby                                Javascript

> 0/0                               > 0/0
# ZeroDivisionError: divided by 0   # NaN


> 0.0/0                             > 0.0/0
# NaN                               # NaN
Ruby           Javascript

> “NaN”.to_f   > parseFloat(“NaN”)
# 0.0          # NaN
Ruby            Javascript

> “” == false   > “” == false
                # true
# false


> [] == false   > [] == false
                # true
# false


> 0 == false    > 0 == false
                # true
# false
Ruby         Javascript

> 0 && []    > 0 && []
# []         #0

> [] && 0    > [] && 0
#0           #0

> 0 && “”    > 0 && “”
# “”         #0

> “” && 0    > “” && 0
#0           # “”

> [] && “”   > [] && “”
# “”         # “”

> “” && []   > “” && []
# []         # “”
Ruby         Javascript

> 5 == ‘5’   > 5 == ‘5’
             # true
# false
Ruby                           Javascript

> {“grrrhhh”}                  > {“grrrhhh”}
                               # 'grrrhhh'
# SyntaxError: compile error
Ruby                      Javascript

> “a”===String.new(“a”)   > “a”===new String(“a”)
                          # false
# true
Thank You
Follow me @mukherjeesuman

More Related Content

What's hot

What's hot (9)

Noticias Pirata
Noticias PirataNoticias Pirata
Noticias Pirata
 
HTML_HHC
HTML_HHCHTML_HHC
HTML_HHC
 
えっ、なにそれこわい
えっ、なにそれこわいえっ、なにそれこわい
えっ、なにそれこわい
 
How to actually use promises - Jakob Mattsson, FishBrain
How to actually use promises - Jakob Mattsson, FishBrainHow to actually use promises - Jakob Mattsson, FishBrain
How to actually use promises - Jakob Mattsson, FishBrain
 
code hay cho blogspot
code hay cho blogspotcode hay cho blogspot
code hay cho blogspot
 
Intro to OAuth
Intro to OAuthIntro to OAuth
Intro to OAuth
 
Mgd10 lab03
Mgd10 lab03Mgd10 lab03
Mgd10 lab03
 
Beware: Sharp Tools
Beware: Sharp ToolsBeware: Sharp Tools
Beware: Sharp Tools
 
Beyond xss
Beyond xssBeyond xss
Beyond xss
 

Recently uploaded

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 

Recently uploaded (20)

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 

Ruby and JS quirks

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

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n