Today I noticed that JavaScript ignores the execution of certain line under certain conditions.
For example, a normal person would read the following code and think that value is false should be logged 5 times.
const values = [false, false, false, false, false];
const isTrue = (value) => {
console.log(`value is ${value}`);
return !!value;
};
let isAllTrue = true;
values.forEach(value => {
isAllTrue &&= isTrue(value);
});
However, this code logged it once.
This code shows that once isAllTrue is false, isAllTrue will never be true due to &&= no matter what you do.
This is why I thought that function executions were being ignored.
And I thought this was an optimization by JavaScript.
I wanted to know the exact reason, so I googled, but I couldn't find the specification. If you know where the specifications are, please let me know.