0
Whatâs the difference between variables?
In JavaScript, whatâs the difference between âletâ and âvarâ when creating variables? I have heard web developers use them interchangeably. Thank you all responders!
6 Answers
+ 4
Let defines a variable inside a block of code so that that variable is not accessible outside of that block. For example:
if (condition){
let a = 3
}
console.log (a) // gives an error because a is not defined outside of if block.
But with var you define a globally accessible variable.
+ 3
https://code.sololearn.com/WdQOWA45wJyR/?ref=app
+ 2
among themselves, they differ in scope. Var has a global and let bounded (within a function) for example
0
Thank you to all who replied to my question! I believe I understand "let" and "var" now.