ternary operator(Advance JavaScript)
Syntax of ternary operator
// condition ? expr1 : expr2;
function isUserValid(bool) {
return bool;
}
// condition ? expr1 : expr2;
var ans = isUserValid(true) ? "You may enter" : "Access Denied";
// 1st copy and test in console
var autoAns =
isUserValid(false) ? "123" : "Wrong Password";
// 2nd copy and test in console
var autoInfo =
"Your account # is " + (isUserValid(false) ? "123" : "not avilable");
Note!!
ternary operator is better than if, else if condition. it easy to use
Source: 5:31 (149. Advanced Control Flow) >> Udemy
Comments
Post a Comment