条件(三元)运算符
如果三元是处理“if”验证的一种非常简单的方法:
代码:
代码语言:javascript复制function validateBetterCommunity(community) {
// Structure to Verify
return community === 'devto' ? 'You are right!' : 'You are wrong :(';
}
console.log(validateBetterCommunity('devto'));
// Expected output: "You're right!"
console.log(validateBetterCommunity('another one'));
// Expected output: "You're wrong :("