Home>Article>Web Front-end> Can double quotes be used in es6?
es6 can use double quotes. In ES6, double quotes can be used to define a string. A string is a text wrapped in single quotes or double quotes. The syntax is "var variable name="string text";"; if quotes are used in quotes, " "Outside double and inside single" or "outside single and inside double" format ensures that the inner and outer quotation marks are different, and the inner quotation marks can also be escaped.
The operating environment of this tutorial: Windows 7 system, ECMAScript version 6, Dell G3 computer.
es6 You can use double quotes.
In es6, double quotes can be used to define strings.
String is a text wrapped in single quotes''
or double quotes""
, such as '123', "abc".
var str = "coffee."; // 双引号 var str = 'left'; // 单引号
It should be noted that single quotes and double quotes are different ways of defining strings and are not part of the string.
When defining a string, if the string contains quotation marks, you can use backslash\ to escape the quotation marks in the string, or choose different quotation marks from the string to define the string (can take " "Outer double and inner single" or "Outer single and inner double" format).
var str = "Let's have a cup of coffee."; // 双引号中包含单引号 var str = 'He said "Hello" and left.'; // 单引号中包含双引号 var str = 'We\'ll never give up.'; // 使用反斜杠转义字符串中的单引号
Extended knowledge: The difference between single quotes and double quotes
(1) There is no difference between single quotes and double quotes for strings that only use characters
(2) Double quotes can be used directly in a string enclosed in single quotes, and single quotes can be used directly in a string enclosed in double quotes
(3) If in a string enclosed in double quotes When using double quotes, you need to escape them with a backslash, note "\"; similarly when using single quotes in a string enclosed by single quotes, you also need to escape "\"
[Related recommendations:javascript video tutorial、webfrontend】
The above is the detailed content of Can double quotes be used in es6?. For more information, please follow other related articles on the PHP Chinese website!