+ 4

Can someone explain the difference between var let const in Javascript

5th Aug 2018, 12:57 PM
CŠ»aŠ²eŠ½ Š‚ŠµŃ€Š²ŠøŠ“Š°
CŠ»aŠ²eŠ½ Š‚ŠµŃ€Š²ŠøŠ“Š° - avatar
4 Answers
+ 8
var and let creates variables which value can be changed. The difference between var and let is that let doesn't support variable hoisting while var does. Hoisting means you can use the variable before the variable declaration. const creates a variable which value cannot be changed. Blocked-scoped means you can access the variable in the block it was declared.
7th Aug 2018, 10:47 AM
Vikash Pal
Vikash Pal - avatar
+ 5
Here's a nice and beginner friendly explanation. https://www.youtube.com/watch?v=q8SHaDQdul0 Also, watch some of his other videos about topics of ES6, it will likely help you along the way.
13th Aug 2018, 7:33 PM
Just A Rather Ridiculously Long Username
+ 3
It's a new kind of syntax launched with es6+ in javascript. Past es6, we were supposed to use var which didn't say much about constants and variables. So now a new notion is that you use const for constants and you can't change that value throughout the course of your programme execution. let basically assigns a variable whose values change frequently. Const is assigned a value by the user while declaration. If you try to assign a new value, Javascript throws an error!
7th Aug 2018, 8:04 AM
Velan
Velan - avatar
5th Aug 2018, 7:02 PM
Benneth Yankey
Benneth Yankey - avatar