javascript - ' ' 和 ""以及没有引号在 Javascript 中是什么意思?

标签 javascript quotes evaluation double-quotes

我意识到我一直在它们之间切换,但不明白为什么,而且我发现很难搜索。

最佳答案

' '"" 是一回事;它们用于定义字符串文字。

不带引号的东西可以是标识符、关键字、非字符串文字、属性名称或数字(可能遗漏了一个)。

例子:

"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/

相关文章:

javascript - 特定按钮点击

javascript - 在javascript中如何动态获取对象的嵌套属性

javascript - 如何使用 React Router 正确重定向?

matlab - 在 MATLAB 中什么时候通过引用赋值?

javascript - 为什么函数声明在求值过程中总是移到顶部?

python - 如果找到零,python 乘法表达式的计算速度会更快吗?

javascript - 将 html 加载到 div 中而不更改页面的其余部分

mysql - MySQL 中何时使用单引号、双引号和反引号

python - 引号引起的语法错误

r - 从 R 调用 sed 时转义引号