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 :: clear whitespace from object javascript 
Javascript :: js get vh value 
Javascript :: async await anonymous function 
Javascript :: postcss.config.js 
Javascript :: read all file names of folder in react 
Javascript :: react onclick function 
Javascript :: zoom out browser javascript 
Javascript :: list from 1 to 100 js 
Javascript :: array contains object in javascript 
Javascript :: discord.js add button to message 
Javascript :: string split javascript 
Javascript :: knex.js count 
Javascript :: eas build apk 
Javascript :: mysql connection in node js 
Javascript :: queryselector data attribute 
Javascript :: How to calc() height in react native for styling 
Javascript :: js localstorage 
Javascript :: react run on route change 
Javascript :: vuejs input text 
Javascript :: jquery input value change event not working 
Javascript :: javascript clear all cookies 
Javascript :: remove node module 
Javascript :: javascript array concat spread operator 
Javascript :: how to make hide/show btn in js 
Javascript :: difference between call and apply in js 
Javascript :: discord.js how to edit a message 
Javascript :: react router dom install 
Javascript :: cra redux 
Javascript :: remove underline from hyperlink react 
Javascript :: javascript sort array smallest to largest 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =