+ 1
What is short-circuiting of logical operations ?
Console.log(null || "user") //-->user Console.log("agnes" || "user") //-->agnes Why ?????
2 odpowiedzi
+ 3
It means that an evaluation is stopped as soon as the result is clear.
a = true
b = false
a||b checks only a and stops right there, because the result ('at least one has to be true') is already determined.
b&&a also stops after b, because the result ('both have to be true') already failed with b being false.
+ 2
When you want to force each part of the condition to be executed you can use the logical operators & and |.
I prepared an example which executes the different variants and prints which parts got evaluated. Finally the result for each operation.
https://code.sololearn.com/WrkrxSH8H377/?ref=app