0
now i understand const cannot be reassign unlike var so so what is the essence of using it (const)
4 Réponses
+ 9
Using 'const' :
Variables declared with 'var' or 'let' can be changed later on in the program, and reassigned. A once a 'const' is initialized, its value can never be changed again, and it can't be reassigned to a different value.
const x = 'test'
We can't assign a different literal to the 'x' const. We can however mutate 'x' if it's an object that provides methods that mutate its contents.
➞ 'const' does not provide immutability, just makes sure that the reference can't be changed.
➞ 'const' has block scope, same as 'let'.
Modern JavaScript developers might choose to always use 'const' for variables that don't need to be reassigned later in the program.
• JavaScript variables:
Should you use let, var or const?
https://medium.com/podiihq/javascript-variables-should-you-use-let-var-or-const-394f7645c88f
+ 8
yaqub abdulmalik 👍
I'm really glad you understood!😊
• Javascript variables
Should you use let, var or const?
https://medium.com/podiihq/javascript-variables-should-you-use-let-var-or-const-394f7645c88f
• These are the features in ES6 that you should know
https://medium.freecodecamp.org/these-are-the-features-in-es6-that-you-should-know-1411194c71cb
https://code.sololearn.com/W70Dsn9iG0da/?ref=app
+ 4
Yes.
Const can't reassign.
Const stands for constant.
Const is used when you need fix value of any variable.
Like you are making any code of area of the circle and you know that value of pi(π) is always 3.14
You can make is like this :
const pi = 3.14
Now whenever you need to use value of pi in your code, just use pi variable.
+ 1
thanks for your contribution I understand Mr Raj chhatrala and Mr Daniel ivanovic