什么是“"和"",在Javascript中没有引号的意思? [英] What does ' ', and " ", and no quotes mean in Javascript?

查看:65
本文介绍了什么是“"和"",在Javascript中没有引号的意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到我一直在不知为何的情况下在它们之间切换,并且发现很难进行搜索.

I realized I've been switching between them with no understanding as to why, and am finding it hard to search for.

推荐答案

''" 是同一件事;它们用于定义字符串文字.

' ' and " " are the same thing; they are used to define string literals.

不带引号的内容可以是标识符,关键字,非字符串文字,属性名称或数字(可能省略了).

Things without quotes can be an identifier, keyword, non-string literal, property name or a number (may have missed one).

示例:

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

用单引号引起来的字符串文字不需要转义的双引号,反之亦然,例如:

String literals that are enclosed in single quotes don't need escaped double quotes and visa versa, e.g.:

'<a href="">click me</a>'    HTML containing double quotes
"It's going to rain"         String containing single quote

这篇关于什么是“"和"",在Javascript中没有引号的意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆