1. Multi-line string
Since it is more troublesome to write multi-line strings with \n, the latest ES6 standard adds a new representation method for multi-line strings, which is ...
represented by backticks:
`这是一个
多行
字符串`;
Note: The backtick is below ESC on the keyboard, to the left of number key 1:
- Template string
To connect multiple strings, you can use the + sign to connect:
var name = '小明';
var age = 20;
var message = '你好, ' + name + ', 你今年' + age + '岁了!';
alert(message);
If there are many variables that need to be connected, it is more troublesome to use the + sign. ES6 has added a new template string, the representation method is the same as the multi-line string above, but it will automatically replace the variables in the string:
var name = '小明';
var age = 20;
var message = `你好, ${
name}, 你今年${
age}岁了!`;
alert(message);