js var vs const

Solutions on MaxInterview for js var vs const by the best coders in the world

showing results for - "js var vs const"
Albane
22 Jan 2019
1//var variables can be re-declared and updated
2    var greeter = "hey hi";
3    var greeter = "say Hello instead";
4//it becomes a problem when you do not realize that a variable 
5//greeter has already been defined before.
6
7//const declarations are block scoped
8//const cannot be updated or re-declared
9	const greeting = "say Hi";
10	greeting = "say Hello instead";// error: Assignment to constant variable. 
11
12	const greeting = "say Hi";
13	const greeting = "say Hello instead";// error: Identifier 'greeting' has already been declared
14