A normal variable (declared with var or let ) can be declared without a value, since you can assign them later:
let foo;
However, you cannot do the same with constants, since you cannot change their value after they have been declared:
const foo; // ...? foo = 3; // this is not allowed because foo is constant
Therefore, you must simultaneously declare and assign a value to a constant. This can be done with several constants at the same time:
const foo = 3, bar = 8;
There is no way to declare const in one place and assign it in another. Instead, you should use var or let .
source share