Variable Hoisiting in javascript

Hey! So today I was reviewing some of the basic syntax of javascript and I came across javascript hoisting. It completely surprised. I have used javascript before (mostly ES6 for variable declaration) but never came across hoisting (🤔 maybe I did but d…


This content originally appeared on DEV Community and was authored by Babi-B

Hey! So today I was reviewing some of the basic syntax of javascript and I came across javascript hoisting. It completely surprised. I have used javascript before (mostly ES6 for variable declaration) but never came across hoisting (🤔 maybe I did but don't remember).

For anyone wondering hoisting in js is a default behavior where all variable declarations(those declared using the var keyword) are moved to the top of the scope before code execution

variable hoisting illustration

So the advantage of this is that you can use a variable even before declaring it and you can declare it where ever you wish(within its given scope).

However with ES6 (let and const) this is prevented that is a variable must be declared before used.


This content originally appeared on DEV Community and was authored by Babi-B


Print Share Comment Cite Upload Translate Updates
APA

Babi-B | Sciencx (2021-11-01T18:17:48+00:00) Variable Hoisiting in javascript. Retrieved from https://www.scien.cx/2021/11/01/variable-hoisiting-in-javascript/

MLA
" » Variable Hoisiting in javascript." Babi-B | Sciencx - Monday November 1, 2021, https://www.scien.cx/2021/11/01/variable-hoisiting-in-javascript/
HARVARD
Babi-B | Sciencx Monday November 1, 2021 » Variable Hoisiting in javascript., viewed ,<https://www.scien.cx/2021/11/01/variable-hoisiting-in-javascript/>
VANCOUVER
Babi-B | Sciencx - » Variable Hoisiting in javascript. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/01/variable-hoisiting-in-javascript/
CHICAGO
" » Variable Hoisiting in javascript." Babi-B | Sciencx - Accessed . https://www.scien.cx/2021/11/01/variable-hoisiting-in-javascript/
IEEE
" » Variable Hoisiting in javascript." Babi-B | Sciencx [Online]. Available: https://www.scien.cx/2021/11/01/variable-hoisiting-in-javascript/. [Accessed: ]
rf:citation
» Variable Hoisiting in javascript | Babi-B | Sciencx | https://www.scien.cx/2021/11/01/variable-hoisiting-in-javascript/ |

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.