You are not logged in.
Pages: 1
삼항 조건 연산자(conditional ternary operator) 는 세 개의 피연산 함수를 취할 수 있는 유일한 자바스크립트 연산자이다. 이 연산자는 if 문의 축약형으로 빈번히 사용된다.
condition ? expr1 : expr2
var firstCheck = false, secondCheck = false, access = firstCheck ? "Access denied" : secondCheck ? "Access denied" : "Access granted"; console.log( access ); // logs "Access granted"
var age = 16; var url = age > 18 ? ( alert("OK, you can go."), // alert returns "undefined", but it will be ignored because // isn't the last comma-separated value of the parenthesis "continue.html" // the value to be assigned if age > 18 ) : ( alert("You are much too young!"), alert("Sorry :-("), // etc. etc. "stop.html" // the value to be assigned if !(age > 18) ); location.assign(url); // "stop.html"
Offline
Pages: 1