0
var and let
in javascript, we can declare variables with var or let, What is difference?
4 Respostas
+ 1
If you know var and let exist in JavaScript then definitely you can declare.
let has blocked scope means cannot access outside the block
var has global scope
if (true) {
let a = 10;
}
console.log(a) //error
if you use var then no error
To know more go here:
https://www.sololearn.com/post/823968/?ref=app
+ 1
Nowadays In JavaScript the var keyword is actually talked down a lot. Now we have 2 more ways to define variables const & let
Const is a constant variable meaning that when you declare a const from anywhere in the dom it is global and cannot be reasigned. Let on the other hand let's you declare an instance of a variable but is limited to the block it is called in. Hang on I'll make you an example.
+ 1
Here's my example, it may not be the best but it definitely shows you the limitations of each.
https://code.sololearn.com/WAAkM9FnREnT/?ref=app
0
Tysm :3