sven sauleau
play

Sven Sauleau @svensauleau @svensauleau 1 Understanding the - PowerPoint PPT Presentation

Sven Sauleau Sven Sauleau @svensauleau @svensauleau 1 Understanding the Differences Is Accepting @svensauleau 2 Prior art @svensauleau 3 Question 1 switch (0) { 0: case 2 a () ; 3 break ; 4 5 case 1: 6 a () { c on s ol e .


  1. Sven Sauleau Sven Sauleau @svensauleau @svensauleau 1

  2. Understanding the Differences Is Accepting @svensauleau 2

  3. Prior art @svensauleau 3

  4. Question 1 switch (0) { 0: case 2 a () ; 3 break ; 4 5 case 1: 6 a () { c on s ol e . log ( "foo" ) ; } function 7 break ; 8 9 } What’s the output? 1. "foo" 2. a is not defined @svensauleau 4

  5. ECMAScript Spec (0) { 1 switch case 0: 2 a () ; 3 break ; 4 5 1: case 6 function a () { c on s ol e . log ( "foo" ) ; } 7 break ; 8 9 } 1. the switch body creates a new scope 2. cases are not creating a new scope 3. function declarations are hoisted @svensauleau 5

  6. Fix 1 switch (0) { case 0: 2 a () ; 3 break ; 4 5 case 1: { // <-- 6 function a () { c on s ol e . log ( "foo" ) ; } 7 break ; 8 } // <-- 9 10 } @svensauleau 6

  7. Question 1 "\n\t\r\n\t\r" == f a l s e What’s the output? 1. true 2. false 3. x > ∞ @svensauleau 7

  8. ECMAScript Spec 1 "\n\t\r\n\t\r" == f a l s e 1. \t, \n and \r are expanded to empty string 2. empty string is falsy @svensauleau 8

  9. Question 1 NaN == NaN What’s the output? 1. true 2. true (because it can’t be false) @svensauleau 9

  10. ECMAScript Spec Unrepresentable/broken value 6.1.6 The Number Type “[...] all NaN values are indistinguishable from each other.” 7.2.15 Strict Equality Comparison “2.a If x is NaN, return false or 2.b If y is NaN, return false.” @svensauleau 10

  11. Question 1 Math . pow (2 , 53) + 1 === Math . pow (2 , 53) What’s the output? 1. true 2. false 3. quantum state @svensauleau 11

  12. ECMAScript Spec 1 Math . pow (2 , 53) + 1 === Math . pow (2 , 53) 6.1.6 The Number Type 1. Number are 64 bits float 2. 11 bits are for the exponent 3. − 2 53 to +2 53 @svensauleau 12

  13. Question 1 [1 , 2] == ’1,2’ What’s the output? 1. true 2. false @svensauleau 13

  14. ECMAScript Spec 1 [1 , 2] == ’1,2’ 7.2.14 Abstract Equality Comparison “9. If Type(x) is Object and Type(y) is either [...], return the result of the comparison ToPrimitive(x) == y.” and then basically [1, 2].toString(). @svensauleau 14

  15. Question 1 <! −− c on s ol e . log ( "foo" ) − > − What’s the output? 1. "foo" 2. parse error (because I’m a JS engine?) 3. no output? @svensauleau 15

  16. ECMAScript Spec Parsing is defined at B.1.3 HTML-like Comments. Allow browsers that didn’t understand the script tag to degrade gracefully ex Netscape 1 @svensauleau 16

  17. Babel @svensauleau 17

  18. Question t 1 var 2 3 t = 0 4 (1 + 1) What’s the output? 1. 1 2. 0 is not a function (because that’s the truth) @svensauleau 18

  19. ECMAScript Spec 1 var t 2 3 t = 0 4 (1 + 1) 11.9 Automatic Semicolon Insertion No ASI because “[...] the parenthesized expression that begins the second line can be interpreted as an argument list for a function call.” @svensauleau 19

  20. Fix 1 var t ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; 2 ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; t = 0 ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; 3 ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ( 1 + 1) ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; 4 @svensauleau 20

  21. Clearer Fix 1 var t ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; 2 3 <! > − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − 4 ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; t = 0 ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; 5 ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ( 1 + 1) ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; 6 7 8 <! −−−−−−−−− I hope that make sense − > − − − − − − − − − − @svensauleau 21

  22. Question 1 b i t c o i n : {}{}{}{}{}{}{}{}{} What’s the output? 1. Mining bitcoins? @svensauleau 22

  23. Spec 1 b i t c o i n : {}{}{}{}{}{}{}{}{} bitcoin is a label forming a LabeledStatement Following by BlockStatements aka the blockchain @svensauleau 23

  24. Conclusion Everything is specified! Don’t let me commit on your project @svensauleau 24

  25. Thanks

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend