我意识到我一直在它们之间切换,但不明白为什么,而且我发现很难搜索。
最佳答案
' '
和 ""
是一回事;它们用于定义字符串文字。
不带引号的东西可以是标识符、关键字、非字符串文字、属性名称或数字(可能遗漏了一个)。
例子:
"hello world" literal (string)
'hello world' literal (string) with same contents
document identifier (object)
{ a: 1 } property name
if keyword (start conditional statement)
3.4 literal (number)
/abc/ literal (regex object)
用单引号括起来的字符串文字不需要转义双引号,反之亦然,例如:
'<a href="">click me</a>' HTML containing double quotes
"It's going to rain" String containing single quote
关于javascript - ' ' 和 ""以及没有引号在 Javascript 中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10852663/