0

var and let

in javascript, we can declare variables with var or let, What is difference?

3rd Jun 2022, 7:29 AM
SorryPark
4 Answers
+ 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
3rd Jun 2022, 9:03 AM
AĶ¢J
AĶ¢J - avatar
+ 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.
3rd Jun 2022, 8:43 AM
pHANTOM|sTEELE
+ 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
3rd Jun 2022, 9:27 AM
pHANTOM|sTEELE
0
Tysm :3
3rd Jun 2022, 9:40 AM
SorryPark