Const with Undefined

When I try to create a variable with const then after logging the variable there is an error message, while, undefined is not printed. Why does it work with let and not const?

const notDefined;

constant variable can’t be changed, for example:

const example = 'hello world'
example = 'this will give an error'

this gives an error, given we can’t update/re-assign the variable. So being able to declare an empty constant variable, would be pointless, we can’t change it, which is why it gives an error

let variable can be changed/updated/re-assigned.


Thanks a lot for this helpful reply.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.