JAVASCRIPT - (LET OR VAR) | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 2

JAVASCRIPT - (LET OR VAR)

What is the difference between Let and VAR in JAVASCRIPT and which is advisable to use more often

30th Mar 2022, 10:52 PM
Samuel Obasi
Samuel Obasi - avatar
6 Antworten
+ 3
https://www.sololearn.com/post/1566575/?ref=app
31st Mar 2022, 1:30 AM
A͢J
A͢J - avatar
+ 2
Bottom line: `var` is old, don't use it. `let` is new, and superior. Even better: Use `const` everywhere. If you get errors, switch to `let`.
30th Mar 2022, 11:39 PM
Schindlabua
Schindlabua - avatar
+ 1
Since 2015 - Current : Using LET to declare the variables is recommended Btw , you can still use VAR In 2022 , i prefer to use CONST and sometimes LET
1st Apr 2022, 7:14 AM
Ardavan Eskandari
Ardavan Eskandari - avatar
0
In the most time you will use let.
30th Mar 2022, 11:39 PM
Stefanoo
Stefanoo - avatar
0
Since the beginning, JavaScript has only one variable declarator which is"var". But var was causing some scope drama (the global scope had access of some local scopes) !!! If you're not familiar with the "scope" term you might have to google it and learn about it!!! As I said, var caused some kind of scope drama. ECMA Script 6 (aka ES6), introduced two new variables declarators (let and const). const: this one used to declare constants, this means that when you declare a constant and asign a value to it you can't change it later. let: this one is a better version of var when it comes to scope respect! When you declare a variable using let inside a local scope (function for example) you can't use or reassign that variable in the global scope (out of the function) but var still has some use cases even though we don't use it so much today. The most recommend is let when you're declaring a variable that will be reassigned in the future, and const when declaring a constant that will not be reassigned.
1st Apr 2022, 2:18 PM
Abdo ACHHOUBI
Abdo ACHHOUBI - avatar