Home > Web Front-end > JS Tutorial > body text

Analyze the representation methods and related operation techniques of multi-line strings and connection strings in ES6

零下一度
Release: 2017-04-28 10:32:25
Original
1848 people have browsed it

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");
Copy after login

New version of writing

alert(`你好
我叫
olive`);//注意这里的两个点是键盘上数字键1左边的按键,而不是单引号哦
Copy after login

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);
Copy after login

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!