如何将变量/转变量变回未定义?

时间:2012-06-20 23:13:31

标签: javascript

我有一个案例,我检查变量是否未定义。在某些情况下,我想再次变量undefined,以便它返回undefined?这会被视为不良做法吗?

:D /代码示例!

if (loc1 == undefined){
    loc1 = loc.title
    }
else if(loc2 == undefined){
    loc2 = loc.title
}
else{
//here I want loc1 and loc2 to turn undefined again!
}

1 个答案:

答案 0 :(得分:3)

你可以这样做:

var test = 1;
test = undefined;