#2) Explain Hoisting in JavaScript❓

myk

Mayank Yadav

Posted on July 25, 2021

#2) Explain Hoisting in JavaScript❓

✔Hoisting is a default behavior of JavaScript where all the
variable and function declarations are moved on top.

This means that irrespective of where the variables and functions are declared, they are moved on top of the scope.

-->The scope can be both local and global.

image

Note:

✔Variable initializations are not hoisted, only variable declarations are hoisted.

✔Using a let variable before it is declared will result in a ReferenceError.

✔Using a const variable before it is declared, is a SyntaxError.

✔To avoid hoisting, you can run JavaScript in strict mode by using “use strict” on top of the code.


💖 💪 🙅 🚩
myk
Mayank Yadav

Posted on July 25, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related