ES6 onwards we have const.
const
This is not allowed:
const x; //declare first //and then initialize it if(condition) x = 5; else x = 10;
Assuming that the const is going to be declared in both instances, you could use a ternary assignment:
const x = condition ? 5 : 10;