Search code examples
javascripteaseljscreatejs

What does ||{} mean in javascript?


I'm working on a project using Easel JS. Opened up the Easel file and the very first line of code confused me:

this.createjs = this.createjs||{};

I know that createjs is invoked when you're setting up your canvas or, for example, creating a bitmap to add to the canvas. But I don't understand the syntax of this line - assign this.createjs or (what I guess is) a blank object to this.createjs?


Solution

  • this.createjs = this.createjs||{};
    

    If this.createjs is not available/ any falsy value then you are assigning {} empty object to this.createjs.

    It's more like,

    var a, 
        b;
    
    b = a || 5;
    

    Since a is not having any value currently, 5 will be assigned to b.