[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Statements/if...else [Back]  [Original]

if...else - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

if...else

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 ..

if , (). (), .

In this article

if ()
   1
[else
   2]

, , .

1

, , "e" (true). if. ({...}), , .

2

, , "e" (false). , if. .

if ... else else if. , JavaScript elseif ( ).

if (1)
   1
else if (2)
   2
else if (3)
   3
...
else
   

, , :

if (1)
   1
else
   if (2)
      2
   else
      if (3)
...

, ({...}) . , , , if:

if () {
   1
} else {
   2
}

true false . , undefined, null, 0, NaN (""), , Boolean, , . :

js
var b = new Boolean(false);
if (b) //   

if...else

js
if (cipher_char === from_char) {
  result = result + to_char;
  x++;
} else {
  result = result + clear_char;
}

else if

, JavaScript elseif. else if:

js
if (x > 5) {
} else if (x > 50) {
} else {
}

, . , :

js
if (x = y) {
  /*  - */
}

, . :

js
if ((x = y)) {
  /*  - */
}

Specification
ECMAScript 2027 LanguageSpecification
# sec-if-statement


Web Proxy Viewer  |  New URL  |  Original Page