In JavaScript, what is the difference between single quotation marks and double quotation marks for strings

read the book and find that String can be expressed in two ways, as follows

var a = "double";
var b = "single";

is there any difference between the two writing methods?

Mar.05,2021

the same, the literal amount of the string

'a'==="a"  //true

there is also template literal quantity

of backquotation mark `.
var str1 = 'a is not "b"'
var str2 = "a is not 'b'"
var str3 = `str: ${str2}`

, it makes no difference at all!


there is not much difference. It is recommended to use single quotation marks


there is no difference in the js language
Application scenarios
var str = "< script src='www.baidu.com' >"
here you must use single and double quotation marks or you will report an error

.

in php,
single quotes are just ordinary strings, but double quotes can parse variables in strings

.

it seems that the parsing speed of single quotation marks is faster than that of double quotes


single quotation marks and double quotation marks are exactly the same, and there is no question of who is fast or slow. Although many people suggest using single quotation marks, I still recommend using double quotation marks.

those who like to use single quotation marks are usually originally developed by PHP. Double quotes in PHP have variable parsing, so they will be slower.
like to use double quotes, usually they are originally engaged in C, Java, C-sharp.

ES6 is followed by backquotes ( `) to indicate a string to be parsed (string template), and this character is easily confused with single quotes (') (of course, general fonts and editors will help you distinguish)

of course, this is not very persuasive, so the most fundamental question is:

  • team engagement
  • habit
  • do not mix except in special cases

    however, after there is a string template, special cases can be handled with a string template, so the team can agree that should not be mixed .

there is no difference. Choose according to your own code specification. Do not mix it. Just unify it


No difference. Generally, you like single quotation marks


. The only difference is that they need to be escaped in different quotation marks, such as '\'" and "\ ".


makes no difference. Js generally uses single quotation marks.


is no difference. It is mainly used to distinguish between quotation marks


. In double quotation marks, you can use single quotation marks
, that is,
var a = "'aaa'111"
to get a string
' aaa'111
at this time'is a character

.
Menu