In JavaScript, There are three ways of declaring a variable, why though? How are they different? const
cannot be redeclared. therefore it will have one constant value, and can't be changed. For Example-
const number = 1
number = 2
//Gives an error (const cannot be redefined.)
Whereas let
can be changed anytime. For example-
let num = 2
num = 5
//Value changes to 5 with no errors.
Thanks for reading.
Hope I helped :D
Top comments (2)
It will not error since you are not redefining
number
in the first case. I think you meantnumber = 2
instead (in both cases).oh yeah thanks for telling