📜  如果未定义 javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:17.205000             🧑  作者: Mango

代码示例1
var a;
try {
    a = b + 1;  // throws ReferenceError if b is not defined
} 
catch (e) {
    a = 1;      // apply some default behavior in case of error
}
finally {
    a = a || 0; // normalize the result in any case
}