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.
Top comments (1)
That is just one of many differences, here's a a more detailed explanation: stackoverflow.com/questions/762011...
But the real point behind let was to change the scope