+ 2
JAVASCRIPT - (LET OR VAR)
What is the difference between Let and VAR in JAVASCRIPT and which is advisable to use more often
7 Respostas
+ 3
https://www.sololearn.com/post/1566575/?ref=app
+ 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`.
+ 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
0
In the most time you will use let.
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.