Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Use Multiple Conditional Ternary Operators Javascript

// Use Multiple Conditional Ternary Operators Javascript.


function checkSign(num) {

	return num > 0 ? "positive" : num < 0 ? "negative" : "zero";

}

console.log(checkSign(10));
console.log(checkSign(-10));
console.log(checkSign(0));
Comment

ternary operator for multiple conditions

String year = "senior";
if (credits < 30) {
  year = "freshman";
} else if (credits <= 59) {
  year = "sophomore";
} else if (credits <= 89) {
  year = "junior";
}
Contrast this with the ternary operator:

String year = credits < 30 ? "freshman" : credits <= 59 ? "sophomore" : credits <= 89 ? "junior" : "senior";
Comment

js ternary else if multi

var foo = (
  bar === 'a' ? 1 : // if 
  bar === 'b' ? 2 : // else if 
  bar === 'c' ? 3 : // else if
  null // else 
);
Comment

multiple ternary operator javascript

var icon = (area == 1) ? icon1 : (area == 2) ? icon2 : icon0;
Comment

PREVIOUS NEXT
Code Example
Javascript :: difference between library and framework in javascript 
Javascript :: get value from textbox in vanilla javascript 
Javascript :: pass parameter to handleclick react 
Javascript :: js math function that returns smallest value 
Javascript :: javascript list has item 
Javascript :: functional component how to add to existing array react 
Javascript :: javascript date object format yyyy mm dd 
Javascript :: calculate average javascript 
Javascript :: polling in js 
Javascript :: js loading spinner 
Javascript :: Moment.js: Date between dates 
Javascript :: usereducer react js 
Javascript :: nodejs base64 
Javascript :: set input value vanilla js 
Javascript :: cart page route in shopify 
Javascript :: how to code print in javascript 
Javascript :: Install popper js v2 
Javascript :: add parameters ajax request 
Javascript :: jasmine spy return value when using create Spy Object angular 2 
Javascript :: check if all values in array are negative javascript 
Javascript :: timeout 
Javascript :: https error response with status 200 angular 
Javascript :: BREAK A LINE on JS 
Javascript :: array iteration 
Javascript :: display date in javascript 
Javascript :: vue router guard 
Javascript :: java json string to map 
Javascript :: check time javascript 
Javascript :: open in a new tab react 
Javascript :: javascript Compare two arrays regardless of order 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =