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
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