MySQL
This commit is contained in:
26
code/ES6/src/02_strings_template/01_string_methods.js
Normal file
26
code/ES6/src/02_strings_template/01_string_methods.js
Normal file
@ -0,0 +1,26 @@
|
||||
let msg = "Hello world!";
|
||||
console.log(msg.startsWith("Hello")); // true
|
||||
console.log(msg.endsWith("!")); // true
|
||||
console.log(msg.includes("o")); // true
|
||||
console.log(msg.startsWith("o")); // false
|
||||
console.log(msg.endsWith("world!")); // true
|
||||
console.log(msg.includes("x")); // false
|
||||
console.log(msg.startsWith("o", 4)); // true
|
||||
console.log(msg.endsWith("o", 8)); // true
|
||||
console.log(msg.includes("o", 8)); // false
|
||||
|
||||
console.log("x".repeat(3)); // "xxx"
|
||||
console.log("hello".repeat(2)); // "hellohello"
|
||||
console.log("abc".repeat(4)); // "abcabcabcabc"
|
||||
|
||||
'x'.padStart(5, 'ab'); // 'ababx'
|
||||
'x'.padStart(4, 'ab'); // 'abax'
|
||||
|
||||
'x'.padEnd(5, 'ab'); // 'xabab'
|
||||
'x'.padEnd(4, 'ab'); // 'xaba'
|
||||
'xxx'.padStart(2, 'ab'); // 'xxx'
|
||||
'xxx'.padEnd(2, 'ab'); // 'xxx'
|
||||
|
||||
'abc'.padStart(10, '0123456789'); //'0123456abc'
|
||||
'x'.padStart(4); // ' x'
|
||||
'x'.padEnd(4); // 'x '
|
23
code/ES6/src/02_strings_template/02_template.js
Normal file
23
code/ES6/src/02_strings_template/02_template.js
Normal file
@ -0,0 +1,23 @@
|
||||
// 1.模板字面量
|
||||
let name = "Nicholas",
|
||||
message01 = `Hello, ${name}.`;
|
||||
console.log(message01); // "Hello, Nicholas."
|
||||
|
||||
// 2.支持JS表达式
|
||||
let count = 10,
|
||||
price = 0.25,
|
||||
message02 = `${count} items cost $${(count * price).toFixed(2)}.`;
|
||||
console.log(message02); // "10 items cost $2.50."
|
||||
|
||||
// 3.多行字符串
|
||||
let message03 = `Multiline
|
||||
string`;
|
||||
console.log(message03); // Hello,
|
||||
// string
|
||||
|
||||
// 4.多行字符串与模板嵌套
|
||||
let fullName = "Nicholas",
|
||||
message04 = `Hello,
|
||||
my name is ${fullName}.`;
|
||||
console.log(message04); // Hello,
|
||||
// my name is Nicholas.
|
Reference in New Issue
Block a user