Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js inline if

var a = 2;
var b = 3;    
var c = ((a < b) ? 'minor' : 'major');
Comment

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 ) {  }.
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript line through 
Javascript :: check date format javascript 
Javascript :: zoom in canvas javascript 
Javascript :: push input value to array javascript 
Javascript :: concat array of objects javascript 
Javascript :: run nextjs in separate port 
Javascript :: collection to array javascript 
Javascript :: throttling function in javascript 
Javascript :: object exists in array javascript 
Javascript :: How To Set Opacity of a View In React Native 
Javascript :: javascript sum array of objects by key 
Javascript :: how to update kali linux on virtualbox 
Javascript :: react-select default menu open 
Javascript :: javascript class 
Javascript :: vue v-for object 
Javascript :: merge array no duiplicates js 
Javascript :: how to create jquery function 
Javascript :: react native create shadows 
Javascript :: react array find index 
Javascript :: jquery if data attribute exists 
Javascript :: javascript flatten an array 
Javascript :: how get first option in select in vue js 
Javascript :: angular load json file with httpclient 
Javascript :: convert array of string to array of objects javascript 
Javascript :: jquery select attribute 
Javascript :: js display 2d array 
Javascript :: how to install react router dom 
Javascript :: jquery set radio button value 
Javascript :: javascript backslash 
Javascript :: wordpress load latest jQuery 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =