what does “object || {} ” means in javascript?

后端 未结 3 1043
执笔经年
执笔经年 2021-01-01 07:56

I found below line of code in javascript application.

var auth = parent.auth = parent.auth || {};

I know there is existing Object parent wh

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-01 07:58

    || is or, the code then returns an empty object, if parent.auth is undefined.

    Like checking for null, then creating a new object if null (from java/c#).

提交回复
热议问题