JavaScript #5 ~ Let, Const, and Var

HJ's Coding Journey·2021년 5월 19일

[Learn] JavaScript

목록 보기

When working on JavaScript, it is typical to use the let keyword to declare a variable as it is the most commonly used keyword within developers. However, there are actually two more ways of declaring a variable and they are const and var. Although not literally visible, there are differences between each declaration keyword.


'Let' is the most commonly used declaratoin keyword in JavaScript. It is used to not only input value into the variable, but also to re-declare the variable, if the value changes in any point of time in the future.


'Const' is another type of declaration variable in which the value inside the variable will not change. Unlike 'let', it is impossible to re-declare a variable that is declared by the 'const' keyword. If one tries to re-declare a 'const' variable, then it will result in an error. Although I mentioned that 'let' is the most commonly used keyword, it is more encouraging to use 'const' more often in order to reduce the risk of potential errors.


'Var' is visibally similar to 'let' in its usability. Going deep into the two differences however, 'var' is a function scope while 'let' is a block scope. For now, it is said that 'var' is an older version of 'let' and we would use 'let' instead of 'var'

Final Note

To summarize this post with one final point, we need to note that 'var' is and older version of JavaScript keyword known as ES2015 while 'let' and 'const' are newer versions of code known as ES206 which explains why developers today only use 'let' and 'const'. More on this topic will be covered in future posts.

Improving Everyday

0개의 댓글