+ 2

In JavaScript what is the difference between let and the var keywords

4th Jan 2019, 9:54 AM
Innocent Savieri
Innocent Savieri - avatar
3 Réponses
+ 5
let is private declaration, which it wont be seen on other functions or blocks var is public declaration, so you can access it everywhere in that code.
4th Jan 2019, 9:55 AM
ShortCode
+ 5
Var : 1. Old 2. Function scoped 3. Hoisted 4. In global scope its added to window/global object. 5. supports redeclaaration Let: 1. Newer came in 2015 (ES6) 2. Block scoped 3. Not hoisted 4. Its not added like var to global objects 5. throws error during redeclaration 2 and 3 are important to know, hoisting being a bit confusing but explained in code below https://code.sololearn.com/WdGAFeNRAe9M/?ref=app https://code.sololearn.com/WiHHHOb3qp8W/?ref=app Answer credits to : Morpheus
4th Jan 2019, 10:13 AM
Raj Chhatrala
Raj Chhatrala - avatar