带引号和没有引号的对象键之间有什么区别? [英] What is the difference between object keys with quotes and without quotes?
本文介绍了带引号和没有引号的对象键之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有任何区别
obj = {'foo': 'bar'}
和
obj = {foo: 'bar'}
我注意到你不能使用 - 当我不使用引号时,键中的
。但它真的有所作为吗?如果是,哪个?
I have noticed that you can't use -
in the key when I don't use the quotes. But does it actually make a difference? If yes, which?
推荐答案
不,引号没有区别(除非,如你所说,你想要使用一个不是有效JavaScript标识符的密钥。)
No, the quotes do not make a difference (unless, as you noted, you want to use a key that’s not a valid JavaScript identifier).
作为旁注, JSON数据交换格式 需要围绕标识符使用双引号。
As a side note, the JSON data exchange format does require double quotes around identifiers.
这篇关于带引号和没有引号的对象键之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文