This article mainly introduces the representation methods of JS ES6 multi-line strings and connection strings, and compares and analyzes the representation methods and related operation skills of multi-line strings and connection strings in ES6 with specific examples. It needs Friends can refer to the following
The examples in this article describe the representation methods of JS ES6 multi-line strings and connection strings. Share it with everyone for your reference, the details are as follows:
1. In the past, it was more troublesome to write multi-line strings in js using \n, so the latest ES6 standard has added a new method of expressing multi-line strings. , represented by `...`:
Old version of writing
alert("你好,\n 我叫\n Olive");
New version of writing
alert(`你好 我叫 olive`);//注意这里的两个点是键盘上数字键1左边的按键,而不是单引号哦
2. In the past, to connect multiple strings, you could use + sign to connect them
var name ="olive"; var age= 26; var message='hello,my name is '+name+',I\'m '+age+' years old'; alert(message);
But if there are many variables that need to be connected, it will be more troublesome to use the + sign. ES6 adds a new string concatenation method:
var name1 ="Mike"; var age1=20; var message1=`hello,${name1},your age is ${age1}`;//同理,这里的两个点是键盘上数字键1左边的按键,而不是单引号哦 alert(message1);
The above is the detailed content of Analyze the representation methods and related operation techniques of multi-line strings and connection strings in ES6. For more information, please follow other related articles on the PHP Chinese website!