hello everyone!
I might have a good suggestion on improving the logical assignment operators. Currently it evaluates the variable and assigns if its truthy, falsey or equals, but what if you want to evaluate the next value and take action afterwards. For example:
const getNextValue = () => {
if (...) {
return undefined;
}
return 'ourNextString';
}
let varx = 'hello';
// all of the statements below evaluate varx
varx ||= getNextValue(); // a will always be 'hello';
varx &&= getNextValue(); // a will always be 'hello';
varx &&= getNextValue(); // a will always be getNextValue();
I want to propose a way to evaluate the next value:
// so instead of only being able to do:
varx && (varx = getNextValue());
// I propose we should also be able to do:
getNextValue() && (varx = getNextValue());
// or in a slighty better way, to not call the function twice
varx = getNextValue() ?? varx;
// maybe it could work to flip it around, like:
varx =|| getNextValue();
varx =&& getNextValue();