Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7769027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:04:02+00:00 2026-06-01T16:04:02+00:00

As demonstrated in this jsfiddle , if you have a JS file and you

  • 0

As demonstrated in this jsfiddle, if you have a JS file and you create a JSON object without using it, it behaves differently depending on whether the keys(members) are wrapped in quotes or not.

valid code:{ a: 1};
invalid code: { "a": 1 };

What you will get is an error message (in Chrome, different for FF/IE, but still fails on syntax)

Uncaught SyntaxError: Unexpected token :

but if you use the object in some way, for example: alert({ "a": 1 }); everything is OK again.

Why does this happen?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:04:03+00:00Added an answer on June 1, 2026 at 4:04 pm

    The statement:

    { a: 1 };
    

    is not an object literal. It’s a block statement with one labeled expression in it. It’s valid.

    This:

    { "a": 1 };
    

    is a syntax error because it’s just not parseable. The quoted “a” starts an expression statement inside the block, but then the next token after the string is a colon, and there’s no expression form that looks like an expression followed by a colon.

    Now:

    var x = { "a": 1 };
    

    works because the “{” is not interpreted as the start of a block statement. That statement starts with var, so it’s a variable declaration. Within the expression on the right side of the “=” token, the only thing that a “{” can mean is the start of an object literal. Similarly, note that:

    ({ "a": 1 });
    

    is OK because the opening parenthesis makes the parser expect a nested subexpression, so again the “{” unambiguously means that it’s the start of an object literal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this navbar I'm making; I have a Jsfiddle to demonstrate. If
I have implemented column resizing with YUIs DataTable as demonstrated in this example: http://developer.yahoo.com/yui/examples/datatable/dt_complex_clean.html
As demonstrated at http://jsfiddle.net/xMnea/4/ I have defined a symbol that contains multiple elements, each
I have a web application that uses jQuery to dynamically create an silverlight object.
So i have this fiddle to demonstrate what I'm trying to achieve: http://jsfiddle.net/vbqmq/28/ I
Here is a JSFiddle that demonstrates the problem... http://jsfiddle.net/L2NBP/5/ For obvious reasons this code
This one's a head scratcher. I've created a commented jsFiddle to demonstrate the phenomenon
As demonstrated in this answer I recently posted, I seem to be confused about
I'm trying to accomplish what's being demonstrated at this site for an experiment I'm
This issue is better demonstrated than explained, so I've set up a git repo

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.