Var vs let vs const | Sololearn: Learn to code for FREE!

+3

Var vs let vs const

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

7/30/2019 4:55:15 PM

Shukor Ali

5 Answers

New Answer

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

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

+1

Ayan ⚡💡 So, it better use let than var. Ok i see tq for that simple explanation

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

0

Dragonxiv js hoisting? Alright i well search for that