What is the defrence between Var , const ,let in JavaScript ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the defrence between Var , const ,let in JavaScript ?

Var,const,let

12th May 2020, 4:15 PM
Yacine Becha
Yacine Becha - avatar
4 Answers
12th May 2020, 4:26 PM
Raj Chhatrala
Raj Chhatrala - avatar
+ 10
# var, let & const • https://academind.com/learn/javascript/var-let-const/ While 'const' and 'let' variables are scoped by code blocks, functions or modules, 'var' variables are scoped only by functions or modules. Check out this article about javascript scope variable — https://dmitripavlutin.com/javascript-scope/ Yacine Becha Please, Try to use the search bar future as you can find many similar threads and to avoid from posting duplicate!
12th May 2020, 5:08 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 6
I'll say in three sentences : var : To make a global variable let : allows you to make local variable const : used to make a constant (not a variable, which means you can't change once you declare it) Example : var name = 'something'; You can now access the name variable anywhere from the script. const sayName = () => { let name = 'something'; } This name variable is just accesible inside the sayName function. const name = 'something'; name = 'lol'; // name will not ever change, bcz it is supposed to be a constant. Hope this helps :))
12th May 2020, 4:27 PM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
0
Thanks for helping
13th May 2020, 5:11 PM
Yacine Becha
Yacine Becha - avatar