Javascript 未定义为函数参数有什么意义?
我一直在OSS源代码函数中看到有Javascript 未定义为函数参数有什么意义?,javascript,Javascript,我一直在OSS源代码函数中看到有未定义的作为参数,例如来自fancybox的如下: (function (window, document, $, undefined) { "use strict"; // snip-snip }(window, document, jQuery)); 或: 有什么原因吗 编辑:好的,我知道它在本地被定义为未定义,但我对此有一个问题,检查某些东西是未定义的有时不起作用: if (thing === undefined) {} //
未定义的
作为参数,例如来自fancybox的如下:
(function (window, document, $, undefined) {
"use strict";
// snip-snip
}(window, document, jQuery));
或:
有什么原因吗
编辑:好的,我知道它在本地被定义为未定义,但我对此有一个问题,检查某些东西是
未定义的
有时不起作用:
if (thing === undefined) {}
// will crash if thing has never been initialized
if (typeof thing === 'undefined') {}
// always works
这或其他方面是否有一些性能提升?以避免在使用
var undefined=”时出现意外结果代码>在全球层面。问题已经提出:)我试着用谷歌搜索它。。。失败。这就是我特别问这个问题的原因。因此,我编辑了一个问题,它通常用于比较obj.x
和undefined
,其中obj
不为空。
if (thing === undefined) {}
// will crash if thing has never been initialized
if (typeof thing === 'undefined') {}
// always works