Can you define var, let and const in simple? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can you define var, let and const in simple?

Differentiating between var, let and const.

3rd Dec 2021, 8:27 PM
Coder Doing Coder Stuff
2 Answers
+ 1
With the advent of ES6, two ways of declaring variables were added: "let and const". Variables of "let" and "const" are local, (block), variables. "let" and "const" allow you to declare variables that are scoped to the block, statement, or expression in which they are used. Variables of "var" defines variables globally, or locally for the entire function, regardless of block scope. Recommended to use "let" where there is no need to use "var". Recommended to use "const" where there is no need to use "let" and "var". ❗Tip: In all the examples given in the lessons, change var to const, if an error occurs, change to "let". This will help you better understand when to use which type of variable.
3rd Dec 2021, 8:46 PM
Solo
Solo - avatar
3rd Dec 2021, 9:23 PM
A͢J
A͢J - avatar