SlideShare una empresa de 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

Más contenido relacionado

La actualidad más candente

La actualidad más candente (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

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
 
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
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
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
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
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
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
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
 
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
 

Último (20)

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...
 
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
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
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)
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
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
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
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
 
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
 

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 del 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