Javascript中单引号和双引号之间的区别 [英] Difference between single quotes and double quotes in Javascript

查看:180
本文介绍了Javascript中单引号和双引号之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在PHP中,双引号和单引号之间的唯一区别是字符串中变量的解释和转义字符的处理。

I know that in PHP, the only difference between double quotes and single quotes is the interpretation of variable inside a string and the treatment of escape characters.

在JavaScript中,我经常看到字符串中使用的双引号。有没有特别的原因,或单引号与双引号完全相同?

In JavaScript, I often see double quotes used in strings. Is there a particular reason for that, or are single quotes exactly the same as double quotes?

推荐答案

你会想要使用您希望双引号出现在字符串内的单引号(例如,对于html属性),而不必转义它们,反之亦然。除此之外,没有区别。

You'll want to use single quotes where you want double quotes to appear inside the string (e.g. for html attributes) without having to escape them, or vice versa. Other than that, there is no difference.

这篇关于Javascript中单引号和双引号之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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