条件 ? true的时候执行 : false时候执行
const x = 20; let answer; if (x > 10) { answer = 'greater than 10'; } else { answer = 'less than 10'; }
简写为:
const answer = x > 10 ? 'greater than 10' : 'less than 10';
条件 ? true的时候执行 : false时候执行
const x = 20; let answer; if (x > 10) { answer = 'greater than 10'; } else { answer = 'less than 10'; }
简写为:
const answer = x > 10 ? 'greater than 10' : 'less than 10';