Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

inline if statement javascript

You can also approximate an if/else using only Logical Operators.

(a && b) || c
The above is roughly the same as saying:

a ? b : c
And of course, roughly the same as:

if ( a ) { b } else { c }
I say roughly because there is one difference with this approach, in that you have to know that the value of b will evaluate as true, otherwise you will always get c. Bascially you have to realise that the part that would appear if () { here } is now part of the condition that you place if ( here ) {  }.
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #inline #statement #javascript
ADD COMMENT
Topic
Name
4+5 =