Just like in other scientific pursuits, in computing it turns out to be pretty important to validate your assumptions when performing your investigations.

For example, today I had someone helping a customer who had “proven” that we changed the behavior of quirks mode with IE10. Specifically, after putting the site into compatibility view, they expected the old IE5 quirks behavior, which they defined as returning NULL from a call to getAttribute( … ) for a non-existent attribute, rather than the empty string.

Here is the code they were using to demonstrate that:

var min = document.getElementById("myInput").getAttribute("min");
if (min == null) {
    alert("This test is working correctly for quirks mode.");
} else {
    alert("Test case failed!!  document.getElementById(\"myInput\").getAttribute(\"min\")=" + min);
}

And, sure enough, if you run this test code, you’ll find that you hit the second branch, and fail the test – you have therefore just proven that IE5 Quirks on IE10 returns the empty string rather than null for a call to getAttribute against a non-existent attribute, right?

Wrong.

Why? Because one of your assumptions wasn’t true. You’re testing something for a non-existent attribute. But … you haven’t yet proven that the attribute you’re using to test doesn’t exist. If you stop on the first line of code in the debugger, you can set a watch variable on document.getElementById(“myInput”) and have a look at the attributes it has in the watch window:

confound

And there is the problem. The getAttribute call wasn’t returning the empty string because of the behavior of getAttribut for non-existent attributes, it was returning the empty string because the attribute exists and has a value of the empty string!

It turns out that if you use a variable that is actually undefined, you get the expected behavior:

var min = document.getElementById("myInput").getAttribute("billAndTed");
if (min == null) {
     alert("This test is working correctly for quirks mode.");
} else {
    alert("Test case failed!!  document.getElementById(\"myInput\").getAttribute(\"min\")=" + min);
}

The test just appeared to fail because the assumptions weren’t validated.