Often times we want to assign different values based on condition but the ternary operator falls short as there nested cases and many more.
I think it will be very convenient to have if-else block for assignment
E.g
const value = if (condition) {
//...
return someValue;
} else {
//...
return someOtherValue;
}
The current workaround we have are:
- Declaring variable using let and then assigning it later
E.g
let a;
if(condition) {
a = someValue;
} else {
a = someOtherValue;
}
- Creating functions or IIFE
let a = functionToGetValue();
// Or
let a = (function () {
if(condition) {
return someValue;
} else {
return someOtherValue;
}
})();
Would love to know your thoughts on this