Mark As Completed Discussion

This code will output 5 despite seeming as if the variable was declared within a function and can't be accessed outside of it. This is because

JAVASCRIPT
1var a = b = 5;

is interpreted the following way:

JAVASCRIPT
1var a = b;
2b = 5;

But b is not declared anywhere in the function with var so it is set equal to 5 in the global scope.

Source
JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment