Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

conditional (ternary) operator function parameter

serveDrink(userIsYoungerThan4 ? 'Milk' : userIsYoungerThan21 ? 'Grape Juice' : 'Wine');
Comment

Use the Conditional (Ternary) Operator

function checkEqual(a, b)
{
return a === b ? “Equal” : “Not Equal” ;
}
checkEqual(1, 2);
Comment

conditional (ternary) operator function parameter

//Instead of:
var welcomeMessage  = 'Hello ' + (username ? username : 'guest');

//Can use:
var welcomeMessage  = 'Hello ' + (username || 'guest');
Comment

Conditional ternary operator

function getFee(isMember) {
  return (isMember ? '$2.00' : '$10.00');
}

console.log(getFee(true));
// expected output: "$2.00"

console.log(getFee(false));
// expected output: "$10.00"

console.log(getFee(null));
// expected output: "$10.00"
Comment

PREVIOUS NEXT
Code Example
Javascript :: render twice react 
Javascript :: array destructuring in react 
Javascript :: js sleep 1 sec 
Javascript :: import leaflet js 
Javascript :: remove mime type from base64 javascript 
Javascript :: merge objects javascript es6 
Javascript :: open youtube video at specific time javascript 
Javascript :: SHOPIFY LANGUAGE SELECTOR 
Javascript :: updatable time js 
Javascript :: mongoose findone multiple conditions 
Javascript :: jquery remove elemtns 
Javascript :: Class constructor cannot be invoked without new 
Javascript :: var javascript 
Javascript :: 8.1.2. Array Length¶ 
Javascript :: blur effect javascript 
Javascript :: regex negate 
Javascript :: mongoose query using an arry 
Javascript :: Javascript format date / time 
Javascript :: npm hook form 
Javascript :: using cors as middleware in js 
Javascript :: { use UnifiedTopology: true } 
Javascript :: CSRF token in js 
Javascript :: componentwillunmount hooks 
Javascript :: angular server start command 
Javascript :: javascript palindrome 
Javascript :: create array of numbers js 
Javascript :: jquery fixed element on scroll footer 
Javascript :: array any 
Javascript :: how to write a variable in js 
Javascript :: select option filter javascript 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =