I wrote.
let const = 10;
and got error.and for objects everything works
let x = {const:10}
What is the difference.
I wrote.
let const = 10;
and got error.and for objects everything works
let x = {const:10}
What is the difference.
Variables can be used in the same places as you can use the const
keyword. If you could use const
as a variable name it would be hard to distinguish between the two.
That is not the case for property names; the syntax will always be clear that it refers to a property name.
const
is a reserved keyword you cannot use as variable name, so the first one is invalid syntax,
let const = 10
In second example you're using const
as key which can be any string
let x = {const:10}
console.log(x)