Variables is used to store the data values. A variable is a container for storing values like numbers, strings, booleans, arrays, objects. There are three types of variables in JS.
Those are const, let, var.
const - It's used to declare a constant variable, a variable whose value cannot be reassigned after it is created. Introduced in ES6 (2015), It's a Block-scoped variable type. It's must be initialized at the time of declaration.
let - It's used to declare a block-scoped variable whose value can be changed. Block scoped ({ }), It Can be reassigned and Cannot be re-declared in the same scope.
var - var is the old way to declare variables. It works, but it has scope and hoisting issues, so it is not recommended in modern JavaScript. function scoped (not block scoped), It Can be re-declared and it Can be reassigned. It's leads to unexpected bugs.
Top comments (0)