1

Why when i write this code :

const myFirstVar = 1
const mySecondVar = 2

(myFirstVar === mySecondVar) ? "yes" : "no"

I get this error :

Uncaught ReferenceError: Cannot access 'mySecondVar' before initialization

While when i write this code :

const myFirstVar = 1
const mySecondVar = 2

myFirstVar === mySecondVar ? "yes" : "no"

It works ?

f1r3x0
  • 11
  • 1
  • 7
    It's semicolons. More specifically automatic semicolon insertion rules. Protip: just always use semicolons unless you really want to learn the ins and outs of ASI and be ready to write all your code with all of those rules in mind. – VLAZ Mar 15 '22 at 10:23

0 Answers0