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

  • Home
  • SEARCH
  • 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 89165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:40:26+00:00 2026-05-10T22:40:26+00:00

What is the correct syntax to create objects in javascript that will work across

  • 0

What is the correct syntax to create objects in javascript that will work across the majority of web browsers (by that I mean : IE 6+, Firefox 2+, Opera 9+ )

Is this valid

var a = {   'class': 'Person',   'name': 'William Shakespeare',   'birthday': -12802392000000,   'nickname': 'Bill' }; 

Or is this:

var a = {   class: 'Person',   name: 'William Shakespeare',   birthday: -12802392000000,   nickname: 'Bill' }; 

And what is the difference between the two?

  • 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. 2026-05-10T22:40:26+00:00Added an answer on May 10, 2026 at 10:40 pm

    @AndreasN is correct: the JSON specification dictates the use of quotes in order for it to actually be JSON. If you don’t use quotes, it may be a valid object literal in Javascript, but it is not JSON. Other services besides browser-side Javascript use JSON (e.g. webservices using php, Java, etc.) and if you construct a string that lacks the quotes, there is no guarantee that it will be parsed correctly — although I suspect most implementations would be robust enough to do so.

    FYI it is dangerous in Javascript to directly use eval() on JSON strings from sources which you cannot prevent malicious attacks. Again, see the JSON site which gives more of an explanation as well as a very short javascript file which safely parses JSON strings into Javascript objects.

    edit: I guess technically your original question is not about JSON but rather the Javascript’s syntax for object literals. The difference is that objects constructable from a JSON string will exclude many other possible object literals, e.g.:

    var a = {cat: 'meow', dog: 'woof'}; var aname = {cat: 'Garfield', dog: 'Odie'}; var b = {   counter: 0,   pow: function(x) { return x+1; },   zap: function(y) { return (counter += y); } }; var c = {   all: [a,aname],   animals: a,   names: aname, }; 

    Object literals ‘a’ and ‘aname’ can be expressed in JSON (by adding quotes to the property names). But object literals ‘b’ and ‘c’ cannot. Object literal ‘b’ contains functions (not allowed in JSON). Object literal ‘c’ above contains references to other variables in a way that is not representable in JSON because some of the references are shared. If you make a change to c.names it will also change c.all[1] since they share a reference to the same variable. JSON can only express objects that have a tree structure (e.g. each sub-element of the overall object is independent).

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

Sidebar

Ask A Question

Stats

  • Questions 92k
  • Answers 92k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can install Mesa 3D. This OSS project supplies an… May 11, 2026 at 6:23 pm
  • Editorial Team
    Editorial Team added an answer No, it's intentional. It accepts the shortest non-ambiguious version of… May 11, 2026 at 6:23 pm
  • Editorial Team
    Editorial Team added an answer I would generally say no; the nature of dependency injection… May 11, 2026 at 6:23 pm

Related Questions

what is the correct syntax to create a new instance of the object as
I'm trying to figure out the correct syntax to use the pipe operator |>
I've been playing around with ASP.NET MVC with a site containing a Master Page.
Is it possible to create a java representation of a package-level oracle associative array.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.