Search code examples
javascriptshorthand

Shorthand for if true then function?


Let me get to this point straight. So I found a shorthand on an Instagram post for something like this:

const bool = true
function myFunction (){
//smth
}
if(bool){
myFunction
}

I can't remember what it was, something with the && operator. Anyone?

sorry for being a bit off topic but I really need this.


Solution

  • Perhaps you're thinking of just using && as it short circuits

    const bool = true;
    const notBool = false;
    function myFunction(){ console.log("hello, world!") };
    
    bool && myFunction();
    notBool && myFunction(); // nada!