{}" mean in JavaScript

This question already has an answer here:

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

  • That line of code does the following:

    IF variable is not defined (or has a falsey value) THEN set it to an empty object.

    ELSE do nothing (technically speaking, variable gets assigned to itself)

    In other words variable will be converted to an empty object if it is any of the following:

  • false
  • undefined
  • null
  • zero
  • NaN
  • an empty string
  • See toBoolean for the spec's definition of falsey values.


    如果变量已经存在,则使用它,否则创建一个空对象


    如果变量未定义或为false,则将其初始化为空对象。

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

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

    下一篇: {}“的意思是在JavaScript中