1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 18:35:07 +00:00
serenity/Libraries/LibJS/Tests/logical-expressions-short-circuit.js
Stephan Unverwerth 520311eb8b LibJS: Add short circuit logical evaluation
When evaluating logical binop expressions, the rhs must not be
evaluated if the lhs leads to the whole expression not being
truthy.
2020-04-03 19:17:52 +02:00

15 lines
244 B
JavaScript

function assert(x) { if (!x) throw 1; }
try {
let foo = 1;
false && (foo = 2);
assert(foo === 1);
foo = 1;
true || (foo = 2);
assert(foo === 1);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}