String Interpolation JavaScript
const age = 3
console.log(`I'm ${age} years old!`)
Drab Dogfish
const age = 3
console.log(`I'm ${age} years old!`)
`string text`
`string text line 1
string text line 2`
`string text ${expression} string text`
tag`string text ${expression} string text`
// Template Literals in javascript
// Longhand:
let firstName = "Chetan", lastName = "Nada";
const welcome = 'Hello my name is ' + firstName + ' ' + lastName;
console.log(welcome); //Hello my name is Chetan Nada
// Shorthand:
const welcome_ = `Hello my name is ${firstName} ${lastName}`;
console.log(welcome_); //Hello my name is Chetan Nada
//Must use backticks, `, in order to work.
let a = 5;
let b = 10;
console.log(`Fifteen is ${a + b} and
not ${2 * a + b}.`);
//Output:
//Fifteen is 15 and not 20.
`half of 100 is ${100 / 2}`
const first_name = "Jack";
const last_name = "Sparrow";
console.log('Hello ' + first_name + ' ' + last_name);