SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (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
 

Kürzlich hochgeladen

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 

Kürzlich hochgeladen (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 

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

Hinweis der Redaktion

  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