[removed] use either a variable, or if it's undefined, a default string

后端 未结 7 928
太阳男子
太阳男子 2020-12-10 00:49

I have this code:

var phrase = function (variable, defaultPhrase) {
    if (typeof variable === \"undefined\") {
        return defaultPhrase;
    }
    else         


        
7条回答
  •  时光说笑
    2020-12-10 01:16

    Shouldn't it be:

    var phrase = function (variable, defaultPhrase){
        if(variable == undefined){
            return defaultPhrase;
        }else{
            return variable;
        }
    }
    

提交回复
热议问题