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 812141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:09:25+00:00 2026-05-15T01:09:25+00:00

Can someone tell me what is the main difference between a JavaScript object defined

  • 0

Can someone tell me what is the main difference between a JavaScript object defined by using Object Literal Notation and JSON object?

According to a JavaScript book it says this is an object defined by using Object Notation:

var anObject = {
    property1 : true,
    showMessage : function (msg) { alert(msg) }
};

Why isn’t it a JSON object in this case? Just because it is not defined by using quotation marks?

  • 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-05-15T01:09:26+00:00Added an answer on May 15, 2026 at 1:09 am

    Lets clarify first what JSON actually is. JSON is a textual, language-independent data-exchange format, much like XML, CSV or YAML.

    Data can be stored in many ways, but if it should be stored in a text file and be readable by a computer, it needs to follow some structure. JSON is one of the many formats that define such a structure.

    Such formats are typically language-independent, meaning they can be processed by Java, Python, JavaScript, PHP, you name it.

    In contrast, JavaScript is a programming language. Of course JavaScript also provides a way to define/describe data, but the syntax is very specific to JavaScript.

    As a counter example, Python has the concept of tuples, their syntax is (x, y). JavaScript doesn’t have something like this.


    Lets look at the syntactical differences between JSON and JavaScript object literals.

    JSON has the following syntactical constraints:

    • Object keys must be strings (i.e. a character sequence enclosed in double quotes ").
    • The values can be either:
      • a string
      • a number
      • an (JSON) object
      • an array
      • true
      • false
      • null
    • Duplicate keys ({"foo":"bar","foo":"baz"}) produce undefined, implementation-specific results; the JSON specification specifically does not define their semantics

    In JavaScript, object literals can have

    • String literals, number literals or identifier names as keys (since ES6, keys can now also be computed, which introduces yet another syntax).
    • The values can be any valid JavaScript expression, including function definitions and undefined.
    • Duplicate keys produce defined, specified results (in loose mode, the latter definition replaces the former; in strict mode, it’s an error).

    Knowing that, just by looking at the syntax, your example is not JSON because of two reasons:

    1. Your keys are not strings (literals). They are identifier names.
    2. You cannot assign a function as a value to a “JSON object” (because JSON doesn’t define any syntax for functions).

    But most importantly, to repeat my explanation from the beginning: You are in a JavaScript context. You define a JavaScript object. If any, a “JSON object” can only be contained in a string:

     var obj = {foo: 42}; // creates a JavaScript object (this is *not* JSON)
     var json = '{"foo": 452}'; // creates a string containing JSON
    

    That is, if you’re writing JavaScript source code, and not dealing with a string, you’re not dealing with JSON. Maybe you received the data as JSON (e.g., via ajax or reading from a file), but once you or a library you’re using has parsed it, it’s not JSON anymore.


    Only because object literals and JSON look similar, it does not mean that you can name them interchangeably. See also There’s no such thing as a “JSON Object”.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Well... here's how I fixed this one, thanks mostly to… May 15, 2026 at 6:09 pm
  • Editorial Team
    Editorial Team added an answer this should do it .. $('.tableclass tbody tr:last td:not(:first-child)').css({'color':'#FF0000'}); May 15, 2026 at 6:09 pm
  • Editorial Team
    Editorial Team added an answer Have you considered creating a decoding table for the responses,… May 15, 2026 at 6:09 pm

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.