...

/

var vs. let vs. const

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 error
const pi=3.14
console.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 error
const num = 5
const num = 6

The code above will also generate an error as we cannot redeclare variables using const ...