Skip to content

Latest commit

 

History

History
61 lines (35 loc) · 1.03 KB

Let & Const.md

File metadata and controls

61 lines (35 loc) · 1.03 KB

Let & Const

Let is block level scope local variable and const is same as let but read-only single assignment variable.

Let

Demo

var obj = {
	name: 'Gokul',
	age: 21,
	car: 'Swift'
};

//let is block level variable here

for (let i in obj) {
	console.log(i); //print name age car
}

console.log(i); //i is not defined

let will also throw an error if any duplicate declaration is made

if (true) {
	let foo = 10;

	let foo = 11; //Duplicate declaration "foo"
}

console.log(foo); //foo is not defined

Const

Demo

const bar = 'Hello';

console.log(bar); //print Hello

bar = 'World'; //"bar" is read-only

⬆ back to top

Reference