SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

Mais procurados (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
 

Último

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
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
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
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
 
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
 
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
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 

Último (20)

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).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
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
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
 
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 ...
 
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
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

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

Notas do Editor

  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