Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

tagged templates

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 :: js round floar 
Javascript :: animation end event angular 
Javascript :: jquery check if all elements hidden 
Javascript :: best way to setup nextjs project 
Javascript :: react state field declaration 
Javascript :: alert in javascript 
Javascript :: is an Angular component, then verify that it is part of this module. 
Javascript :: The reduce() method executes a reducer function on each element of the array and returns a single output value. 
Javascript :: how to add object to array javascript 
Javascript :: The element.style Property 
Javascript :: delay external javascript file load 
Javascript :: node http 
Javascript :: axios delete set content type 
Javascript :: directive multiple input 
Javascript :: localhost server in react native 
Javascript :: Angular patchValue dynamically 
Javascript :: javascript fadein fadeout 
Javascript :: javascript getter arrow function 
Javascript :: convert javascript to ruby 
Javascript :: how to pass props to another component 
Javascript :: vue add watcher 
Javascript :: jquery parse url parameters 
Javascript :: inline null check javascript 
Javascript :: declare int in javascript 
Javascript :: how to check for null in javascript 
Javascript :: prisma.db sqlite 
Javascript :: react split 
Javascript :: code to convert rgb to hsl color 
Javascript :: how to define connection string in appsettings.json 
Javascript :: for check status in ajax javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =