now i understand const cannot be reassign unlike var so so what is the essence of using it (const) | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

now i understand const cannot be reassign unlike var so so what is the essence of using it (const)

4th Jan 2019, 12:14 PM
yaqub abdulmalik
yaqub abdulmalik - avatar
4 Respostas
+ 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
4th Jan 2019, 1:28 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 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
5th Jan 2019, 7:45 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 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.
4th Jan 2019, 12:37 PM
Raj Chhatrala
Raj Chhatrala - avatar
+ 1
thanks for your contribution I understand Mr Raj chhatrala and Mr Daniel ivanovic
5th Jan 2019, 6:43 PM
yaqub abdulmalik
yaqub abdulmalik - avatar