+ 3

Var vs let vs const

Can someone explain more about those things and which is better to use when we code JS

30th Jul 2019, 4:55 PM
Shukor Ali
Shukor Ali - avatar
5 Answers
+ 2
In many cases its good to use let. Sometimes const and nerly never var. You can google for js hoisting if you want to learn more about this.
30th Jul 2019, 6:06 PM
Dragonxiv
Dragonxiv - avatar
+ 2
Var and let is almost same. But the best practice is using let keyword for declaring variables. And const means constant. Constant values cannot be changed.
31st Jul 2019, 8:39 AM
Ayan Fox
Ayan Fox - avatar
+ 1
Ayan ⚡💡 So, it better use let than var. Ok i see tq for that simple explanation
2nd Aug 2019, 12:03 AM
Shukor Ali
Shukor Ali - avatar
+ 1
let and Var are not the same at all ... for(var i = 0; i < 10 ; i++) { console.log(i); } for(let i = 0; i < 10 ; i++) { console.log(i); } Check the diff between this 2 loop. var create your variables at the start of your script, so they are not linked to a "scope" instaed of let. const is used to not modify your variable. Note that const lock primitive (number, string, boolean) but not Array or object due to the reference. You can use methods but you can't reasign new ref for Array and object.
14th Aug 2019, 12:24 AM
Aleksander
0
Dragonxiv js hoisting? Alright i well search for that
31st Jul 2019, 8:51 AM
Shukor Ali
Shukor Ali - avatar