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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:56:57+00:00 2026-06-03T03:56:57+00:00

I had to use json2.js in my project as browser(IE8) JSON object was not

  • 0

I had to use json2.js in my project as browser(IE8) JSON object was not available for parsing strings to JSON.

I ran through json2.js and am having a doubt with the variable declaration.

A JSON global variable is declared in json2.js like

var JSON;
if(!JSON){
    JSON={};
}

What is the effect of declaration var JSON; on the global JSON object.
I hope the declaration should override the global JSON object in any browser (IE8/IE7).
But for my surprise it is not overriding when a global object is available.
Only a variable definition / initiation overrides a global variable?
Kindly clarify.

  • 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-03T03:56:59+00:00Added an answer on June 3, 2026 at 3:56 am

    For each variable declaration (not initialization!). The following happens (section #10.5):

    8. For each VariableDeclaration and VariableDeclarationNoIn d in code, in source text order do

    1. Let dn be the Identifier in d.
    2. Let varAlreadyDeclared be the result of calling env’s HasBinding concrete method passing dn as the argument.
    3. If varAlreadyDeclared is false, then
      1. Call env’s CreateMutableBinding concrete method passing dn and configurableBindings as the arguments.
      2. Call env’s SetMutableBinding concrete method passing dn, undefined, and strict as the arguments.

    So you see, whenever var x is encountered, it is tested whether a variable with name x already exists in the environment. If yes, it is just ignored, but if not, then the variable is declared and initialized with undefined.

    Since the code is run in global scope it tests whether JSON exists in global scope. So if JSON already exists, var JSON; is just ignored.


    Just some thoughts regarding testing/explaining this behaviour:

    I don’t know at which point in the JavaScript execution the global object is created, but I assume before all other scripts are evaluated. That means, JSON exists and has a value before any variable declaration, something you can only simulate if you include two scripts (can also be inline I guess, they are evaluated after another).

    Try:

    // script1.js
    var foo = 'bar';
    
    // script2.js
    var foo;
    if(!foo) {
        foo = 'baz';
    }
    alert(foo);
    
    // include script2.js after script1.js
    

    What’s the result? (cheaters look here).


    Whenever you are in a single script file, all variable declarations are hoisted to the top anyways. So if you have

    var foo = 'bar';
    var foo;
    if(!foo) {
        foo = 'baz';
    }
    

    the script is actually executed as:

    var foo;
    var foo;
    foo = 'bar';
    if(!foo) {
        foo = 'baz';
    }
    

    You could not actually test whether the second var foo; overwrites the first one, since at this point it has no value yet. So this is not a good example to demonstrate the behaviour quoted above.

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

Sidebar

Related Questions

Possible Duplicate: How to catch exceptions I have not really had to use try
I've had to use $.ajaxSetup() to globally change the contentType to application/json $.ajaxSetup({ contentType:
I had a project that requires the use of Extjs as the frontend of
we have an asp.net application, that makes heavy use of REST/json services through httpwebrequest
I had a json parsing problem updating my app from prototype 1.6.1 to 1.7.0
I've opened up an ExtJs project that I've not had my head in for
I had created one HTML page for my experiance. In this i had use
How to Remove Badge from the tabbar item i had use below code but
I had to use a Microsoft Web Services Enhancements 2.0 service and it raised
I came across a scenario where I had to use Union all, how can

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.