`` template Strings

  • Se utilizan back-ticks ``
  • Soporte multilinea
  • placeholders ${ expression }
`string text`

`string text line 1
 string text line 2`

`string text ${expression} string text`

placeholders y multilinea

antes (ES5)

var name = "juanma";
var getSuitableDrink = function(who) {
  return who === 'juanma' ? 'beer' : 'cocktail'
};

console.log( 'Hello, '+name+'!\nFancy a '+getSuitableDrink()+'?' );

// Hello, juanma!
// Fancy a beer?

después (ES2015)

var name = "juanma";
var getSuitableDrink = function(who) {
  return who === 'juanma' ? 'beer' : 'cocktail'
};

console.log( `Hello, ${ name }!
  Fancy a ${ getSuitableDrink() }?` );

Más info:

⛏   ES6 Katas: Template Strings

Hacer las siguientes katas:

results matching ""

    No results matching ""