Your logic fails if optionalArg is passed, but evaluates as false - try this as an alternative
(如果传递了OptionalArg,您的逻辑将失败,但计算结果为false - 请尝试将此作为替代方法)
if (typeof optionalArg === 'undefined') { optionalArg = 'default'; }
Or an alternative idiom:
(或另类成语:)
optionalArg = (typeof optionalArg === 'undefined') ? 'default' : optionalArg;
Use whichever idiom communicates the intent best to you!
(使用哪个成语最能传达您的意图!)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…