💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
if表达式中还可以有一个可选项,即else。如果条件返回false的话,我们也可以执行后面else子句中的代码块。 ``` >>> var result = '',a = 3; undefined >>> if(a > 2){ ... result = 'a is greater than 2'; ... }else{ ... result = 'a is not greater than 2'; ... } a is greater than 2 ``` 我们还可以在if和else之间插入任意个else if子句,例如: ``` >>> var result = '',a = 3; undefined >>> if(a > 2 || a < -2){ ... result = 'a is not between -2 and 2'; ... }else if(a === 0 && b === 0){ ... result = 'both a and b are zeros'; ... }else if(a === b){ ... result = 'a not b are equal'; ... }else{ ... result = 'i give up'; ... } a is not between -2 and 2 ``` 还可以在当前的if代码块中在内嵌一个新的条件语句。