Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript template string condtioning

let person = 'Mike';
let age = 28;

function myTag(strings, personExp, ageExp) {
  let str0 = strings[0]; // "That "
  let str1 = strings[1]; // " is a "
  let str2 = strings[2]; // "."

  let ageStr;
  if (ageExp > 99){
    ageStr = 'centenarian';
  } else {
    ageStr = 'youngster';
  }

  // We can even return a string built using a template literal
  return `${str0}${personExp}${str1}${ageStr}${str2}`;
}

let output = myTag`That ${ person } is a ${ age }.`;

console.log(output);
// That Mike is a youngster.
Comment

PREVIOUS NEXT
Code Example
Javascript :: use anchor element to open file 
Javascript :: how to get html element coords in js 
Javascript :: javascript read all cookies 
Javascript :: change origin xy phaser 
Javascript :: regex tunisian phone number 
Javascript :: find minimum 
Javascript :: phaser random ellipse 
Javascript :: phaser animation from png sequence 
Javascript :: phaser animation on repeat event 
Javascript :: regular expression a-z and 0-9 
Javascript :: apply multiple style objects in react js 
Javascript :: rotate matrix 90 degrees javascript 
Javascript :: js undici fetch stream data 
Javascript :: nodejs mongodb native reuse single connection 
Javascript :: javascript change IFormFile to base64string 
Javascript :: cargar un select con javascript dependiendo de otro select 
Javascript :: how to put multiple conditions in if statement node .js 
Javascript :: react native countdown 
Javascript :: mongoose schema example 
Javascript :: useselector 
Javascript :: push pop in javascript 
Javascript :: javascript keyboard shortcuts 
Javascript :: in js pass infinite argument in function 
Javascript :: mongoose id validator 
Javascript :: how to read excel file in nodejs 
Javascript :: get the max value from array js 
Javascript :: context menus use 
Javascript :: material ui table row height 
Javascript :: toggle div javascript 
Javascript :: socket io get user rooms 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =