#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 …


This content originally appeared on DEV Community and was authored by Mayank Yadav

✔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.


This content originally appeared on DEV Community and was authored by Mayank Yadav


Print Share Comment Cite Upload Translate Updates
APA

Mayank Yadav | Sciencx (2021-07-25T06:00:27+00:00) #2) Explain Hoisting in JavaScript❓. Retrieved from https://www.scien.cx/2021/07/25/2-explain-hoisting-in-javascript%e2%9d%93/

MLA
" » #2) Explain Hoisting in JavaScript❓." Mayank Yadav | Sciencx - Sunday July 25, 2021, https://www.scien.cx/2021/07/25/2-explain-hoisting-in-javascript%e2%9d%93/
HARVARD
Mayank Yadav | Sciencx Sunday July 25, 2021 » #2) Explain Hoisting in JavaScript❓., viewed ,<https://www.scien.cx/2021/07/25/2-explain-hoisting-in-javascript%e2%9d%93/>
VANCOUVER
Mayank Yadav | Sciencx - » #2) Explain Hoisting in JavaScript❓. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/07/25/2-explain-hoisting-in-javascript%e2%9d%93/
CHICAGO
" » #2) Explain Hoisting in JavaScript❓." Mayank Yadav | Sciencx - Accessed . https://www.scien.cx/2021/07/25/2-explain-hoisting-in-javascript%e2%9d%93/
IEEE
" » #2) Explain Hoisting in JavaScript❓." Mayank Yadav | Sciencx [Online]. Available: https://www.scien.cx/2021/07/25/2-explain-hoisting-in-javascript%e2%9d%93/. [Accessed: ]
rf:citation
» #2) Explain Hoisting in JavaScript❓ | Mayank Yadav | Sciencx | https://www.scien.cx/2021/07/25/2-explain-hoisting-in-javascript%e2%9d%93/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.