6.1 概览
新的字符串方法:
> 'hello'.startsWith('hell')
true
> 'hello'.endsWith('ello')
true
> 'hello'.includes('ell')
true
> 'doo '.repeat(3)
'doo doo doo '
ES6 有一种新的字符串字面量,模板字面量:
// String interpolation via template literals (in backticks)
let first = 'Jane';
let last = 'Doe';
console.log(`Hello ${first} ${last}!`);
// Hello Jane Doe!
// Template literals also let you create strings with multiple lines
let multiLine = `
This is
a string
with multiple
lines`;