Skip to content

Latest commit

 

History

History
42 lines (25 loc) · 900 Bytes

alert-and-or.md

File metadata and controls

42 lines (25 loc) · 900 Bytes

alert-and-or"

  • <a href="alert-and-or.html" alert-and-or" /alert-and-or" alert-and-oralert-and-or"

alert-and-or" /alert-and-or" /alert-and-or" ask/alert-and-or"k%2Falert-and-or"%2Falert-and-or"

<a href="../logical-operators.html" Logical operators

<a href="../logical-operators.html"

The result of OR AND OR

importance: 5

What will the result be?

alert( null || 2 && 3 || 4 );

solution

The answer: 3.

<a href="alert-and-or.html#"

alert( null || 2 && 3 || 4 );

The precedence of AND && is higher than ||, so it executes first.

The result of 2 && 3 = 3, so the expression becomes:

null || 3 || 4

Now the result is the first truthy value: 3.