I am having a hard time wrapping my head around one example from Elequentjavascript.
In the else statement there you will find || operator. One of the expressions will be executed but which one? I know it is the one that is set to true, but I cant seem to figure out how it is being evaluated.
function findSolution(target) {
function find(start, history) {
if (start == target)
return history;
else if (start > target)
return null;
else
return find(start + 5, "(" + history + " + 5)") ||
find(start * 3, "(" + history + " * 3)");
}
return find(1, "1");
}
console.log(findSolution(24));
As I understand short-circuit || operator both sides will be evaluated. But how does it choose the right one?