Baseline Widely available
ì¡°ê±´ (ì¼í) ì°ì°ìë JavaScriptìì ì¸ ê°ì í¼ì°ì°ì를 ë°ë ì ì¼í ì°ì°ìì
ëë¤. ìììë¶í° 조건문, 물ìí(?
), ì¡°ê±´ë¬¸ì´ ì°¸(truthy)ì¼ ê²½ì° ì¤íí ííì, ì½ë¡ (:
), ì¡°ê±´ë¬¸ì´ ê±°ì§(falsy)ì¼ ê²½ì° ì¤íí ííìì´ ë°°ì¹ë©ëë¤. í´ë¹ ì°ì°ìë if...else
문ì ëì²´ì¬ë¡ ë¹ë²í ì¬ì©ë©ëë¤.
function getFee(isMember) {
return isMember ? "$2.00" : "$10.00";
}
console.log(getFee(true));
// Expected output: "$2.00"
console.log(getFee(false));
// Expected output: "$10.00"
console.log(getFee(null));
// Expected output: "$10.00"
구문
condition ? exprIfTrue : exprIfFalse;
매ê°ë³ì
condition
조건문ì¼ë¡ ì¬ì©ëë ííì
exprIfTrue
condition
ì´ truthyí ê°ì¼ë¡ íê°ë ê²½ì° ì¤íëë ííì (true
ì ê°ê±°ë, true
ë¡ ì¹íë ì ìë ê°)
exprIfFalse
condition
ì´ falsyí ê°ì¼ë¡ íê°ë ê²½ì° ì¤íëë ííì (false
ì ê°ê±°ë, false
ë¡ ì¹íë ì ìë ê°)
false
ì´ì¸ì falsyí ííììë null
, NaN
, 0
, ë¹ì´ìë 문ìì´ (""
), ê·¸ë¦¬ê³ undefined
ê° ììµëë¤. condition
ì´ ì´ ì¤ íëì¼ ê²½ì° ì¡°ê±´ ì°ì°ìì ê²°ê´ê°ì exprIfFalse
ííìì ì¤íí ê²°ê´ê°ì
ëë¤.
var age = 26;
var beverage = age >= 21 ? "Beer" : "Juice";
console.log(beverage); // "Beer"
null ê° ì²ë¦¬í기
null
ì¼ ì ìë ê°ì ì²ë¦¬í ë íí ì¬ì©ë©ëë¤:
let greeting = (person) => {
let name = person ? person.name : `stranger`;
return `Howdy, ${name}`;
};
console.log(greeting({ name: `Alice` })); // "Howdy, Alice"
console.log(greeting(null)); // "Howdy, stranger"
ì°ê²°ë 조건문 ì²ë¦¬í기
ì¡°ê±´ ì°ì°ìë ìëì ê°ì´ ì°ê²°í´ ì¬ì©í ì ììµëë¤. ì´ë ì°ê²°ë if ⦠else if ⦠else if ⦠else
ì ì ì¬í©ëë¤.
function example(â¦) {
return condition1 ? value1
: condition2 ? value2
: condition3 ? value3
: value4;
}
ì ì½ëë ìëì ì°ê²°ë if ⦠else
ì ëë±í©ëë¤.
function example(â¦) {
if (condition1) { return value1; }
else if (condition2) { return value2; }
else if (condition3) { return value3; }
else { return value4; }
}
ëª
ì¸ ë¸ë¼ì°ì í¸íì± ê°ì´ 보기
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4