SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

Tendances (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
 

Dernier

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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
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
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
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
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
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
 
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
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 

Dernier (20)

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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
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
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
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?
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
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
 
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
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 

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

Notes de l'éditeur

  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