Web 开发的新标杆!7 个 JavaScript One-Liners 改变您的编程方式

2023-09-24 16:54:07 浏览数 (1)

条件(三元)运算符

如果三元是处理“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 :("

0 人点赞