2

Variable Hoisiting in javascript

 3 years ago
source link: https://dev.to/babib/variable-hoisiting-in-javascript-m8
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
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 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

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK