en.javascript.info/1-js/02-first-steps/11-logical-operators/8-if-question/solution.md
Ilya Kantor ab9ab64bd5 up
2017-03-21 14:41:49 +03:00

20 lines
415 B
Markdown

The answer: the first and the third will execute.
Details:
```js run
// Runs.
// The result of -1 || 0 = -1, truthy
if (-1 || 0) alert( 'first' );
// Doesn't run
// -1 && 0 = 0, falsy
if (-1 && 0) alert( 'second' );
// Executes
// Operator && has a higher precedence than ||
// so -1 && 1 executes first, giving us the chain:
// null || -1 && 1 -> null || 1 -> 1
if (null || -1 && 1) alert( 'third' );
```