I have a boolean which is originally false. But in some future, if its value change (can change multiple times, but only to the same) will be true.
For example, with the given pseudocode
const hasChanged = false; // stateful
// This function can be called multipe times
const handleSubmit = () => {
// ...
hasChanged = true;
// ...
}
I am always reassigning the value 'true' to my boolean... and I think that, maybe, it can be optimized by firstly checking if it is false, like this:
const handleSubmit = () => {
// ...
!hasChanged && hasChanged = true;
// ...
}
But this will only be true if the conditional check (read + check) is faster than the write operation in JS, something that I don't know.
Any ideas?