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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:08:04+00:00 2026-05-29T07:08:04+00:00

I have a good grasp on the difference between undefined and null and the

  • 0

I have a good grasp on the difference between undefined and null and the fact that JavaScript casts just about anything to a boolean, in particular, null to false.

My question is this: Why is the second alert triggered in both FF 9 and IE 9? (This is a small test script that is based on much more complex script. It is meant only to illustrate the issue…)

I’m expecting the . operator to take precedence and the expression to return null, which would then be cast to a boolean value of false. Adding parenthesis, !(context.isNull), makes no difference.

<!DOCTYPE html>  
<html lang="en">  
  <head>  
    <title>Test</title>  
  </head>  

  <body>  
    <script type="text/javascript">  
        var context = this;  
        var isNull = null;  

        var aFunc = function() {  
            alert(context.isNull);  
            if (!context.isNull) {  
                alert("Is !context.isNull really true?");  
            }  
        };  

        aFunc();  

    </script>  
  </body>  
</html>  
  • 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-29T07:08:05+00:00Added an answer on May 29, 2026 at 7:08 am

    First, “Thank you!” to everyone who responded.

    I’m deeply embarrassed. It was late Friday on a long day, and I inverted the logic in my head. It is doing exactly what it should. The problem was that the actual code was checking for something existing, and I wrote my test case backwards.

    What happens is that null is cast to false, !false is true, so the “if” code is executed. My (brain dead) choice of field names obscures the problem.

    The reason for

    var context = this;
    

    is that the real code sits inside a constructor. The field “context” is then “closed” when the function is created, which preserves a reference to the object being constructed. This is important when the function is attached to another object (generally as an event handler), so that the function body can access the contents of the original object. Of course, in the example, “this” refers to the global object, which doesn’t serve much purpose.

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

Sidebar

Related Questions

Can I have good example or code about how to use Ajax Datepicker in
(Let's assume that I have good reasons not to remove my NSAssert() checks in
I have been working with PHP for years and gotten a very good grasp
Hi I have following JavaScript code that I am trying to run. My aim
I have a simple question here. Is there a difference between passing a variable
I have a good grasp of Direct3D 9, and now I want to learn
I have a good grasp of unit testing, DI, mocks, and all the design
I think I have now a good grasp of why you need to either
Most C# developers developers, like me have a good solid grasp on the .net
I am a seasoned .Net developer and have a good grasp of OOP concepts.

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.