11 sven sauleau

1. Sven Sauleau Sven Sauleau @svensauleau @svensauleau 1
2. Understanding the Differences Is Accepting @svensauleau 2
3. Prior art @svensauleau 3
4. Question 1 2 3 4 switch (0) { case 0 : a () ; break ; 5 case 1 : f u n c t i o n a ( ) { c o n s o l e . l o g ( " foo " ) ; } break ; 6 7 8 9 } What’s the output? 1. "foo" 2. a is not defined @svensauleau 4
5. ECMAScript Spec 1 2 3 4 switch (0) { case 0 : a () ; break ; 5 case 1 : f u n c t i o n a ( ) { c o n s o l e . l o g ( " foo " ) ; } break ; 6 7 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 2 3 4 switch (0) { case 0 : a () ; break ; 5 c a s e 1 : { // <-f u n c t i o n a ( ) { c o n s o l e . l o g ( " foo " ) ; } break ; } // <-- 6 7 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 , 5 3 ) + 1 === Math . pow ( 2 , 5 3 ) What’s the output? 1. true 2. false 3. quantum state @svensauleau 11
12. ECMAScript Spec 1 Math . pow ( 2 , 5 3 ) + 1 === Math . pow ( 2 , 5 3 ) 6.1.6 The Number Type 1. Number are 64 bits float 2. 11 bits are for the exponent 3. −253 to +253 @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 o n s o l e . l o g ( " 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 1 var t 2 3 4 t = 0 (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 4 t = 0 (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 3 4 ;;;;;;;;;;;;;;;;;;;; t = 0;;;;;;;;;;;;;;;;;;;;;; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ( 1 + 1) ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; @svensauleau 20
21. Clearer Fix 1 var t ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; 2 3 <!−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−> 4 5 6 ;;;;;;;;;;;;;;;;;;;; t = 0;;;;;;;;;;;;;;;;;;;;;; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ( 1 + 1) ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; 7 8 <!−−−−−−−−− I hope t h a t make s e n s e −−−−−−−−−−−> @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