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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:48:00+00:00 2026-05-28T00:48:00+00:00

Every time anyone mentions testing against undefined , it’s pointed out that undefined is

  • 0

Every time anyone mentions testing against undefined, it’s pointed out that undefined is not a keyword so it could be set to "hello", so you should use typeof x == "undefined" instead. This seems ridiculous to me. Nobody would ever do that, and if they did it would be reason enough to never use any code they wrote… right?

I found one example of someone who accidentally set undefined to null, and this was given as a reason to avoid assuming that undefined isn’t overwritten. But if they’d done that, the bug would have gone undetected, and I fail to see how that’s better.

In C++ everyone is well aware that it’s legal to say #define true false, but nobody ever advises you avoid true and use 0 == 0 instead. You just assume that nobody would ever be a big enough jerk to do that, and if they do, never trust their code again.

Has this ever actually bitten somebody where someone else assigned to undefined (on purpose) and it broke your code, or is this more of a hypothetical threat? I’m willing to take my chances to make my code marginally more readable. Is this a really bad idea?

To reiterate, I am not asking for how to protect against reassigned undefined. I’ve seen those tricks written 100 times already. I’m asking how dangerous it is to not use those tricks.

  • 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-28T00:48:01+00:00Added an answer on May 28, 2026 at 12:48 am

    No, I never have. This is mostly because I develop on modern browsers, which are mostly ECMAScript 5 compliant. The ES5 standard dictates that undefined is now readonly. If you use strict mode (you should), an error will be thrown if you accidentally try to modify it.

    undefined = 5;
    alert(undefined); // still undefined
    
    'use strict';
    undefined = 5; // throws TypeError
    

    What you should not do is create your own scoped, mutable undefined:

    (function (undefined) {
        // don't do this, because now `undefined` can be changed
        undefined = 5;
    })();
    

    Constant is fine. Still unnecessary, but fine.

    (function () {
        const undefined = void 0;
    })();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Every time I create an object that has a collection property I go back
Every time I try to run a small application that uses a Derby DB
Every time I make a project I develop several generic routines/modules/libraries that I expect
Usually every time `make install' is run, files are not put in a specific
Every time I used the MediaController.show(int timeout) , it doesn't work? Does anyone know
Anyone know how to store numbers onto JButtons ? For example every time the
why every time that i retrieve an existent User and try to update its
I have the following code that works each and every time an element change
Every time that I change a value in the designer after saving it, the
Has anyone managed to build Erlang on OpenSolaris? Every time I try I get:

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.