'和'之间有什么区别?在JavaScript? [英] What is the difference between ' and " in JavaScript?

查看:76
本文介绍了'和'之间有什么区别?在JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到这个问题,我想知道JavaScript中的相同内容。

I saw this question and I am wondering about the same thing in JavaScript.

如果在JavaScript中创建字符串时使用字符'或字符',则应用程序似乎表现相同。那么这两个字符之间有什么区别?

If you use the character ' or the character " when making strings in JavaScript, the application seems to behave the same. So what is the difference between these two characters?

我在使用'构建字符串时所看到的唯一优势是我可以执行以下操作:

The only advantage I have seen in using ' to build strings is that I can do stuff like:

var toAppend = '<div id="myDiv1"></div>';

而不是:

var toAppend = "<div id=\"myDiv1\"></div>";

我应该注意它们之间是否有任何显着差异?

Is there any significant difference between them that I should be aware of?

推荐答案

它们等同于所有意图和目的。如果你想在字符串中使用任何一个,那么最好是用另一个来创建正如你所注意到的那样,除此之外,它都是一样的。

They are equivalent for all intents and purposes. If you want to use either one inside a string, it is a good idea to use the other one to create the string, as you noted. Other than that, it's all the same.

这篇关于'和'之间有什么区别?在JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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