Backsticks
With backsticks we can embed any expression into the string.
/**
* Backsticks quotes
*
* Embed any expression into the string
* Span multiple lines
* Special characters start with a backslash character
*/
let str = 'World';
console.log(`Hello ${str}`); // Hello World
let guestList = `Guests:
* John
* Pete
* Mary
`;
console.log(guestList); // John Pete Mary
console.log('Object\'s properties'); // Object's properties
console.log('One backslash \\'); // One backslash \
Substring
Modern Javascript has methods like include, startsWith.
/**
* Substring methods
*
* includes, startsWith, slice
*/
console.log("Widget with id".includes('id')); // true
console.log('Widget'.includes('id', 2)); // false
console.log('Widget'.startsWith('Wid')); // true
console.log('Widget'.endsWith('get')); // true
console.log('Widget'.slice(0, 3)); // Wid
console.log('Widget'.charAt('0')); // W
console.log('Widget'.indexOf('id')); // 1
console.log('Widget with id'.indexOf('Widget')); // 0
console.log('Widget with id'.indexOf('widget')); // -1
console.log('Widget with id'.indexOf("id")); // 1
console.log('Widget with id'.indexOf('id', 2)); // 12
Last update: 432 days ago