Skip to content

Instantly share code, notes, and snippets.

@sayinserdar
Last active February 20, 2021 15:09
Show Gist options
  • Save sayinserdar/7c62556f507ac1c2c405c35447beb6a3 to your computer and use it in GitHub Desktop.
Save sayinserdar/7c62556f507ac1c2c405c35447beb6a3 to your computer and use it in GitHub Desktop.
Short circuiting in JS
let a; // falsy value
let b = predefinedFunctionWhichReturnsFalse(); // false
let c = computationallyHeavyFunctionWhichReturnsFalse(); // falsy value
let d = false;
let e = true;
// Needs to evalaute every condition.
let result = a | b | c | d | e;
// Needs to evaluate only 'e'.
let result = e | a | b | c | d;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment