I am using && like this and it works
&&
typeof foo === \'function\' && foo(); //if foo exist then call it
instead
You could use a void operator. This evaluates the expression and returns undefined.
undefined
void (foo && foo());
var foo; void (foo && foo()); foo = () => console.log('foo'); void (foo && foo());