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 ответов
+ 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.