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

PREVIOUS NEXT
Code Example
Javascript :: eleventy filter newlines 
Javascript :: truthy or falsy 
Javascript :: JavaScript Methods and this Keyword 
Javascript :: javascript Adding Element to the Outer Array 
Javascript :: JavaScript Access Symbol Description 
Javascript :: javascript Arrow Function as an Expressio 
Javascript :: JavaScript WeakMap Methods 
Javascript :: javascript get() handler 
Javascript :: javascript Deleting an object is not allowed 
Javascript :: JavaScript Code Blocks 
Javascript :: error:0308010C:digital nextjs 
Javascript :: get max type value in solidity 
Javascript :: pizza form validation jquery 
Javascript :: test driven development javascript 
Javascript :: theme ui with react 17 
Javascript :: state dependent on prev state in react js 
Javascript :: phaser random triangle 
Javascript :: phaser pause all animations 
Javascript :: NodeJS/express : Cached and 304 status code on chrome 
Javascript :: show data time &refresh 
Javascript :: javascript fiori 
Javascript :: white space below image next image 
Javascript :: Slice and Splice -Javascript 2 
Javascript :: javascript in jsx 
Javascript :: 404 responses in express 
Javascript :: google places API details JS 
Javascript :: clear cache javascript 
Javascript :: Lazy Loading 
Javascript :: remove array from array javascript 
Javascript :: jsoup 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =