| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Statements/if...else | [Back] [Original] |
Get to know MDN better
function testNum(a) {
let result;
if (a > 0) {
result = "";
} else {
result = "";
}
return result;
}
console.log(testNum(-5));
// : ""
if (condition)
statement1
// else
if (condition)
statement1
else
statement2
if...else else if JavaScript 1 elseif
if (condition1)
statement1
else if (condition2)
statement2
else if (condition3)
statement3
//
else
statementN
if (condition1)
statement1
else
if (condition2)
statement2
else
if (condition3)
statement3
//
({ ... })
if (condition) {
statements1
} else {
statements2
}
function checkValue(a, b) {
if (a === 1)
if (b === 2)
console.log("a is 1 and b is 2");
else
console.log("a is not 1");
}
checkValue(1, 3) "a is not 1" dangling else else if
function checkValue(a, b) {
if (a === 1)
if (b === 2)
console.log("a is 1 and b is 2");
else
console.log("a is not 1");
}
if
function checkValue(a, b) {
if (a === 1) {
if (b === 2) {
console.log("a is 1 and b is 2");
}
} else {
console.log("a is not 1");
}
}
true false Boolean false, undefined, null, 0, -0, NaN, ("") false Boolean
const b = new Boolean(false);
if (b) {
console.log("b is truthy"); // "b is truthy"
}
if (cipherChar === fromChar) {
result += toChar;
x++;
} else {
result += clearChar;
}
JavaScript elseif else if
if (x > 50) {
/* */
} else if (x > 5) {
/* */
} else {
/* */
}
if...else x = y
if ((x = y)) {
//
}
while 1 1
x = y;
if (x) {
//
}
| ECMAScript 2027 LanguageSpecification # sec-if-statement |
| Web Proxy Viewer | New URL | Original Page |