Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Created August 13, 2017 13:12
Show Gist options
  • Save prof3ssorSt3v3/6f8572b10505de8ebe657792a3c75200 to your computer and use it in GitHub Desktop.
Save prof3ssorSt3v3/6f8572b10505de8ebe657792a3c75200 to your computer and use it in GitHub Desktop.
// template strings / template literals ES6
//
// wrapped with back-tick character like table names in SQL
// Variables and expressions wrapped in ${ }
// Tagged Template Literals
const log = console.log;
let message = 'I\'m going to the store';
let message1 = "And then he said, \"That's what she said.\"";
let item = 'Heineken';
let message2 = 'I\'m going to buy ' + item + ' at the store';
let message3 = ''.concat('I\'m going to buy ', item, ' at the store');
let arr = ['a','b','c'];
let message4 = 'The first letter is ' + arr[0] + '.';
let msg = `I'm going to buy ${item.toUpperCase()} at the store`;
log(msg);
function bubba(strings, ...expressions){
log(strings.length);
log(expressions.length);
return strings[1] + strings[0] + expressions[0];
}
let str = bubba`x ${item} x`;
console.log(str);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment