mardi 18 juin 2019

Is it valid to use && instead of if?

I am using && like this and it works

foo && foo(); //if foo exist then call it

instead of

if (foo) { foo(); }

Is it wrong to do or just a matter of style and taste? For me it is natural and I want to use &&, but now a linter complained: Expected an assignment or function call and instead saw an expression.

Can there be any real issues here or is it just a matter of convention?

Aucun commentaire:

Enregistrer un commentaire