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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:39:34+00:00 2026-05-25T03:39:34+00:00

I have just run a very simple JavaScript performance test (don’t ask why). The

  • 0

I have just run a very simple JavaScript performance test (don’t ask why). The test declares a variable, but doesn’t assign anything to it:

var x;

It then compares the speed of comparing the value variable to null, and to undefined, in other words:

var y = (x == null); and var y = (x == undefined);.

I was expecting the comparison with undefined to be the fasted. In fact it was nowhere near. The comparison with null was far and away the fastest, around 80% faster.

The results I’ve described above come from running the tests in Chrome (version 13). Running them in Firefox produces results far closer to what I would have expected (the comparison with undefined is faster than with null, albeit very marginally).

So, my question is what could the cause of this be? Why does Chrome seem to favour the comparison with null so greatly?

For quick reference, here’s a screenshot of the results:

enter image description here

  • 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-25T03:39:34+00:00Added an answer on May 25, 2026 at 3:39 am

    null is a reserved keyword which cannot be overriden, so when you are doing a comparison against null, all you have to do is a single comparison.

    However, when you are checking against undefined, the engine must do a type lookup and then a comparison, meaning that it is actually slightly more demanding.


    If you need to actually check to see if something is undefined, you should use

    if(typeof notSet == "undefined"){ }
    

    Proof

    Try it… and set something to null in your JavaScript console.

    null = "will error";
    // Errors with --> ReferenceError: invalid assignment left-hand side
    

    However, if you try and do it with undefined, it won’t error. That is not to say that you can override undefined, because you can’t, but that undefined is its own primitive type.

    The only real similarity between null and undefined, is that they can both be coerced into a boolean false.

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

Sidebar

Related Questions

I am just trying to compile and run a very simple test program, but
I just made a very simple website, but I have run into a problem.
I have a very simple test app just to play around with Windows Phone
I'm trying to run a very simple browser detect script and it executes just
I have very simple application just in the body of Main method. I have
I'm writing a very simple text editor and have run into a somewhat minor
I have a very simple method scheduled to run every 10 seconds like this:
I have a very simple form. So simple its scary. When I run the
This should be very simple, but its not working! I have this link on
I have a very simple UI and i need to constantly run a check

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.