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

后端 未结 3 1045
执笔经年
执笔经年 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 08:22

    parent.auth || {} means if parent.auth is undefined, null or false in boolean case then new empty object will be initialized and assigned.

    or you can understand it like:

    var auth;
    if(parent.auth){       
        auth=parent.auth;   
    } else {
        auth={};   
    }
    

提交回复
热议问题