开发者

what does "window.gapi = window.gapi || {};" mean?

I'm a little confused w开发者_运维技巧ith the syntax here.

window.foo = window.bar || {};

Any ideas? I'm just trying to understand javaScript better. Thanks


If window.bar is null or undefined (also: 0, "", NaN and false) then window.foo will be set to an empty object ({}), otherwise it will be window.bar.

The logical OR operator (||) works as a null coalescing operator in this situation. It's basically shorthand for:

window.foo = (window.bar != null ? window.bar : {});

This post explains the behavior in more detail.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜