且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

javascript冒号运算符混乱

更新时间:2022-06-20 04:06:49

:不是运算符,它构成标签语法的一部分.

: isn't an operator, it forms part of label syntax.

请参见 MDN

label :
statement

label
不是保留字的任何JavaScript标识符.

label :
statement

label
Any JavaScript identifier that is not a reserved word.

apples是一个标识符.

"orranges"是字符串文字.

有什么办法可以在json对象之外使用它?

is there any way that I can use it outside of json object ?

您似乎将JSON与对象文字语法混淆了.

You seem to be confusing JSON with object literal syntax.

当您不在定义对象的过程中时,不能使用:作为将属性名称与对象中的值分隔开的字符.

You can't use a : as the character that separates a property name from a value in an object when you aren't in the process of defining an object.