Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript if short notation

Tags:

javascript

I was surfing on the web in search of a shorthand Javascript notation for an if-statement. ONLY the if, not the else. My question: does it exist? eg:

(i === 0) ? onlyMyTrueValue;

The only snippet I seem to find is this one:

(i === 0) ? myTrueValue : myFalseValue;
like image 950
user2381011 Avatar asked May 20 '13 16:05

user2381011


1 Answers

You can do:

(i === 0) && onlyMyTrueValue;

The right hand side of the above statement will execute only if the left hand side passes.

like image 133
techfoobar Avatar answered Oct 11 '22 15:10

techfoobar