javascript colon operator confusion

后端 未结 1 1673
一向
一向 2020-12-20 19:08

I am learning javascript myself. There is a confusion with some javascript,

price = 14;
name = \"Mary\";
apples:5; //This line executing without error
\"orra         


        
相关标签:
1条回答
  • 2020-12-20 19:40

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

    See MDN

    label :
    statement

    label
    Any JavaScript identifier that is not a reserved word.

    apples is an identifier.

    "orranges" is a string literal.

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

    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.

    0 讨论(0)
提交回复
热议问题