Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js var vs const

//var variables can be re-declared and updated
    var greeter = "hey hi";
    var greeter = "say Hello instead";
//it becomes a problem when you do not realize that a variable 
//greeter has already been defined before.

//const declarations are block scoped
//const cannot be updated or re-declared
	const greeting = "say Hi";
	greeting = "say Hello instead";// error: Assignment to constant variable. 

	const greeting = "say Hi";
	const greeting = "say Hello instead";// error: Identifier 'greeting' has already been declared
Source by www.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #js #var #const
ADD COMMENT
Topic
Name
9+4 =