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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:50:50+00:00 2026-06-09T11:50:50+00:00

Here i am just creating a global namespace for my application and everything works

  • 0

Here i am just creating a global namespace for my application and everything works as expected

var MYAPP = MYAPP || {} ; 

but if I omit var keyword ( i know it’s not the right way), javascript throw an error “ReferenceError: MYAPP2 is not defined” .

MYAPP2 = MYAPP2 || {};

just out of curiosity can some one explain me in second case why javascript is not able to resolve the reference.

  • 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-09T11:50:51+00:00Added an answer on June 9, 2026 at 11:50 am

    The first version doesn’t produce an error because Javascript’s variable hoisting makes it equivalent to this:

    var MYAPP;            // declares, but leaves the value undefined / unchanged
    MYAPP = MYAPP || {};  // creates, if the value was previously undefined
    

    Importantly, the declaration part of this does not overwrite any existing declaration or assignment that was already made to the variable.

    This is what allows this pattern to be used repeatedly within a single scope. MYAPP either retains the value it already had, or is initialised to an empty object.

    in the second case, that declaration step is effectively omitted. If the variable has not already been declared (or otherwise exists in scope, i.e. as a property of the global object) then the error you see is generated.

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

Sidebar

Related Questions

I know there isn't enough validation in here just going through some testing. $result
I am not looking for the answer here but just how to find the
I have seen similar questions here but I just can't understand them. I am
Just some example code here, but I have lists of strings that I want
just creating a subclass of uiscrollview here and im trying to catch a -(void)scrollViewDidScrollUIScrollView
I'm just creating a ContextMenu.. At this line, I don't know what I shall
don't know better title for this, but here's my code. I have class user
I need a fix for this. here is just part of my code <?php
I just found Dean Edwards javascript packer here: http://dean.edwards.name/packer/ It has a couple of
Just a quick question here. I have a program in which I need to

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.