“elseif” syntax in JavaScript

后端 未结 8 821
刺人心
刺人心 2020-11-29 17:59

How can I achieve an elseif in a JavaScript condition?

8条回答
  •  有刺的猬
    2020-11-29 18:32

    Actually, technically when indented properly, it would be:

    if (condition) {
        ...
    } else {
        if (condition) {
            ...
        } else {
            ...
        }
    }
    

    There is no else if, strictly speaking.

    (Update: Of course, as pointed out, the above is not considered good style.)

提交回复
热议问题