Javascript var, let & const
For a long time, we all know var keyword in javascript to declare a variable. However, ES6 (ECMAScript 2015) introduces 2 new keywords to declare variables, namely let & const . There are several differences between var , let & const , which we can classify into several types, namely related to scope , hoisting , the ability of these variables to be reassigned & redeclare . Below I will try to explain them one by one. Scope Scope is the current context of code, which determines the variable’s accessibility to JavaScript. In short, I often refer to scope as a place for variables to live, where they can be called/accessed. The keyword var has a function scope , that is, it only recognizes function blocks (other than global scope) as its scope, while let & const has block scope , that is, every block marked with curly brackets { … } is also considered as a context/scope. Hoisting Hoisting is a process in which javascript appears to move a function , variable , ...