开发者

what does this mean? javascript question

开发者 https://www.devze.com 2023-01-22 14:39 出处:网络
var a = wi开发者_运维问答ndow.a || {};It means a will be assigned window.a if it is not null or undefined, otherwise, it will equal an empty objectTo answer the unasked question: this is used to make

var a = wi开发者_运维问答ndow.a || {};


It means a will be assigned window.a if it is not null or undefined, otherwise, it will equal an empty object


To answer the unasked question: this is used to make sure "a" will be valid.

Without it, when calling a.someFieldHere you might get exception saying "a is undefined", with such code in place you won't get such error.

It's useful when "a" is created elsewhere in some other code that not always get executed.

Kind of insurance policy. :)

0

精彩评论

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