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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:56:59+00:00 2026-06-01T08:56:59+00:00

Everything I’ve ever read indicates that in Javascript, the boolean value of an undefined

  • 0

Everything I’ve ever read indicates that in Javascript, the boolean value of an undefined variable is False. I’ve used code like this hundreds of times:

if (!elem) {
   ...
}

with the intent that if “elem” is undefined, the code in the block will execute. It usually works, but on occasion the browser will throw an error complaining about the undefined reference. This seems so basic, but I can’t find the answer.

Is it that there’s a difference between a variable that has not been defined and one that has been defined but which has a value of undefined? That seems completely unintuitive.

  • 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-01T08:57:01+00:00Added an answer on June 1, 2026 at 8:57 am

    What is a ReferenceError?

    As defined by ECMAScript 5, a ReferenceError indicates that an invalid reference has been detected. That doesn’t say much by itself, so let’s dig a little deeper.

    Leaving aside strict mode, a ReferenceError occurs when the scripting engine is instructed to get the value of a reference that it cannot resolve the base value for:

    A Reference is a resolved name binding. A Reference consists of three
    components, the base value, the referenced name and the Boolean valued
    strict reference flag. The base value is either undefined, an Object,
    a Boolean, a String, a Number, or an environment record (10.2.1). A
    base value of undefined indicates that the reference could not be
    resolved to a binding. The referenced name is a String.

    When we are referencing a property, the base value is the object whose property we are referencing. When we are referencing a variable, the base value is unique for each execution context and it’s called an environment record. When we reference something that is neither a property of the base object value nor a variable of the base environment record value, a ReferenceError occurs.

    Consider what happens when you type foo in the console when no such variable exists: you get a ReferenceError because the base value is not resolvable. However, if you do var foo; foo.bar then you get a TypeError instead of a ReferenceError — a subtle perhaps but very significant difference. This is because the base value was successfully resolved; however, it was of type undefined, and undefined does not have a property bar.

    Guarding against ReferenceError

    From the above it follows that to catch a ReferenceError before it occurs you have to make sure that the base value is resolvable. So if you want to check if foo is resolvable, do

    if(this.foo) //...
    

    In the global context, this equals the window object so doing if (window.foo) is equivalent. In other execution contexts it does not make as much sense to use such a check because by definition it’s an execution context your own code has created — so you should be aware of which variables exist and which do not.

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

Sidebar

Related Questions

Everything I have read says that when making a managed stored procedure, to right
Everything I've read seems to imply that building a cross-compiler is significantly harder than
Everything I read about cookies says that setting the expiry time of a cookie
Everything I read about better PHP coding practices keeps saying don't use require_once because
Everything I'm finding via google is garbage... Note that I want the answer in
Everything I find through Google refers to Code First so I'm wondering what the
Everything that isn't labeled calc or finalvalue is raw data that I will be
Everything i read tells me this should work page 1 is <?php $state =
Everything you do with XML is case sensitive, I know that. However, right now
Everything is working up to here, I just need to create the method that

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.