3 min read
Difference between var let and const?
Here in this example we first assign var as empty and its output will be like Undefined we reassign it with the city name as Coimbatore the output will be Coimbatore.
var city console.log(city) // undefined var city = "coimbatore"; console.log(city) // coimbatore var name = "Arun"; console.log(name) // Arun
// LET CAN BE REASSIGNED, BUT CAN'T BE REDECLARED.
It shows an error due to the 'source' being called even before the initialization
console.log(source) // ERROR let source = 'chennai' console.log(source) // chennai
ERROR / Chennai
The console.log(source) is declared before the initialization.
// CONST CAN'T BE REASSIGNED AND CAN'T BE REDECLARED //console.log(destination) // ERROR const destination = "Goa" console.log(destination) // Goa
Cheatsheet to know the difference between var let and const.
Also, Read our article: https://blog.skillsafari.in/front-end-developer-interview-questions-and-answers-for-freshers-section-2
Did you find this article valuable?
Support Skill Safari by becoming a sponsor. Any amount is appreciated!