ES6 onwards we have const
.
This is not allowed:
const x; //declare first
//and then initialize it
if(condition) x = 5;
else x = 10;
This makes sense because it prevents us from using the constant before it's initialized.
But if I do
if(condition)
const x = 5;
else
const x = 10;
x becomes block scoped.
So how to conditionally create a constant?