var vs. let vs. const
Let's compare the var, let, and const keywords in JavaScript!
The const
Keyword #
const
is block-scoped. This means that the variable declared with const cannot be redeclared or reassigned.
Node.js
//code will throw an errorconst pi=3.14console.log(pi)pi=3;
The code above will generate an error as we cannot assign a new value to the variable pi
as we have declared it using const
.
Node.js
//code will throw an errorconst num = 5const num = 6
The code above will also generate an error as we cannot redeclare variables using const
...