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 :: how to use of socket io on a route in nodejs 
Javascript :: js display property 
Javascript :: js confirm 
Javascript :: es6 get first and last element of array 
Javascript :: javascript target closest 
Javascript :: fabric js 
Javascript :: agrgar atributo con id jquey 
Javascript :: chaine de caractère dans une autres js 
Javascript :: identity-obj-proxy not working 
Javascript :: div diseapear animation 
Javascript :: how contvert array to string like implode in jquery 
Javascript :: copying table element to clipboard using javascript 
Javascript :: js anonymous functions 
Javascript :: javascript this Inside Constructor Function 
Javascript :: Jquery check if hover over child element 
Javascript :: what is useref in react 
Javascript :: javascript latitude longitude to km 
Javascript :: create array in javascript contains 10 elements 
Javascript :: heroku proxy cross origin 
Javascript :: vue 3 props 
Javascript :: js set css 
Javascript :: The loading of x in a frame is denied by “X-Frame-Options“ directive set to “SAMEORIGIN“ js 
Javascript :: slice array jas 
Javascript :: import bootstrap 4 in react 
Javascript :: google maps color pin 
Javascript :: create slug in express 
Javascript :: javascript to Postgress 
Javascript :: Image preload React 
Javascript :: cypress check element has an attribute 
Javascript :: rounding to two decimal places 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =