mituri

[ES6] Tagged template literals

Feb 25th, 2020
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.29 KB | None | 0 0
  1. var a = 5;
  2. var b = 10;
  3.  
  4. function tag(strings, ...values) {
  5. console.log(strings[0]); // "Hello "
  6. console.log(strings[1]); // " world "
  7. console.log(values[0]); // 15
  8. console.log(values[1]); // 50
  9.  
  10. return "Bazinga!";
  11. }
  12.  
  13. tag`Hello ${ a + b } world ${ a * b}`;
  14. // "Bazinga!"
Advertisement
Add Comment
Please, Sign In to add comment