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

sven sauleau
SMART_READER_LITE
LIVE PREVIEW

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 .


slide-1
SLIDE 1

Sven Sauleau

Sven Sauleau

@svensauleau

@svensauleau 1

slide-2
SLIDE 2

Understanding the Differences Is Accepting

@svensauleau 2

slide-3
SLIDE 3

Prior art

@svensauleau 3

slide-4
SLIDE 4

Question

1 switch

(0) {

2

case 0:

3

a () ;

4

break ;

5 6

case 1:

7

function a () { c on s ol e . log ( "foo" ) ; }

8

break ;

9 }

What’s the output?

  • 1. "foo"
  • 2. a is not defined

@svensauleau 4

slide-5
SLIDE 5

ECMAScript Spec

1 switch

(0) {

2

case 0:

3

a () ;

4

break ;

5 6

case 1:

7

function a () { c on s ol e . log ( "foo" ) ; }

8

break ;

9 }

  • 1. the switch body creates a new scope
  • 2. cases are not creating a new scope
  • 3. function declarations are hoisted

@svensauleau 5

slide-6
SLIDE 6

Fix

1 switch

(0) {

2

case 0:

3

a () ;

4

break ;

5 6

case 1: { // <--

7

function a () { c on s ol e . log ( "foo" ) ; }

8

break ;

9

} // <--

10 } @svensauleau 6

slide-7
SLIDE 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

slide-8
SLIDE 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

slide-9
SLIDE 9

Question

1 NaN == NaN

What’s the output?

  • 1. true
  • 2. true (because it can’t be false)

@svensauleau 9

slide-10
SLIDE 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

slide-11
SLIDE 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

slide-12
SLIDE 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. −253 to +253

@svensauleau 12

slide-13
SLIDE 13

Question

1 [1 ,

2] == ’1,2’

What’s the output?

  • 1. true
  • 2. false

@svensauleau 13

slide-14
SLIDE 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

  • f the comparison ToPrimitive(x) == y.”

and then basically [1, 2].toString().

@svensauleau 14

slide-15
SLIDE 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

slide-16
SLIDE 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

slide-17
SLIDE 17

Babel

@svensauleau 17

slide-18
SLIDE 18

Question

1 var

t

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

slide-19
SLIDE 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

slide-20
SLIDE 20

Fix

1 var

t ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;

2 3

; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; t = 0 ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;

4

; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ( 1 + 1) ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;

@svensauleau 20

slide-21
SLIDE 21

Clearer Fix

1 var

t ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;

2 3 <!

− − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − >

4 5

; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; t = 0 ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;

6

; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ( 1 + 1) ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;

7 8 <!−−−−−−−−− I

hope that make sense − − − − − − − − − − − >

@svensauleau 21

slide-22
SLIDE 22

Question

1 b i t c o i n :

{}{}{}{}{}{}{}{}{}

What’s the output?

  • 1. Mining bitcoins?

@svensauleau 22

slide-23
SLIDE 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

slide-24
SLIDE 24

Conclusion

Everything is specified! Don’t let me commit on your project

@svensauleau 24

slide-25
SLIDE 25

Thanks