{} means in JavaScript?

This question already has an answer here:

  • What does the construct x = x || y mean? 11 answers
  • What does “var FOO = FOO || {}” (assign a variable or an empty object to that variable) mean in Javascript? 7 answers

  • window.google = window.google || {};
    

    意思是如果window.google没有设置,它会创建一个新的对象。


    It initializes the object if the object is not initialized.

    After creating the object, you have to init it because the results can be unpredictable without init... Without init, the value is undefined (not 0, not null, undefined).


    This means that if window.google doesn't have value (undefined, null) then use {} .

    It is a way of assigning a default value to a variable in JavaScript.

    链接地址: http://www.djcxy.com/p/95282.html

    上一篇: 我不明白这个代码

    下一篇: {}是否代表JavaScript?