Briefly, what is the difference between "var" and "let" keywords in Javascript?
Peace
Posted on January 19, 2022
var and let are both used for variable declaration in javascript but the difference between them is that a 'var' variable can be re-initialized while a 'let' variable can only be initialized once.
Example:
var name = "Peter"
var name = "Peace"
console.log(name)
Output
Peace
A keyword called let was introduced in ES6, a major update to JavaScript, to solve this potential issue with the var keyword.
Once a variable has been initialized, you can not re-initialize it.
Example:
let name = "Keza"
let name = "Gisa"
console.log(name)
Output
SyntaxError: unknown: Identifier 'name' has already been declared.
💖 💪 🙅 🚩
Peace
Posted on January 19, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
variable Briefly, what is the difference between "var" and "let" keywords in Javascript?
January 19, 2022