YOU DON'T KNOW JS: JAVASCRIPT HOISTING TL; DR

By: Saurav

2018-01-26 23:59:00 UTC

Bullet Points from You don't know Js:

1. We can be tempted to look at var a = 2; as one statement, but the JavaScript Engine does not see it that way. It sees var a and a = 2 as two separate statements, the first one a compiler-phase task, and the second one an execution-phase task.

2. All declarations in a scope, regardless of where they appear, are processed first before the code itself is executed.

3, You can visualize this as declarations (variables and functions) being "moved" to the top of their respective scopes, which we call "hoisting".

4, Declarations themselves are hoisted, but assignments, even assignments of function expressions, are not hoisted.

5. While multiple/duplicate var declarations are effectively ignored, subsequent function declarations do override previous ones.

Owned & Maintained by Saurav Prakash

If you like what you see, you can help me cover server costs or buy me a cup of coffee though donation :)