Why do the following expanded if shorthand statements not work in javascript?
- by PeanutsMonkey
This is my first attempt to write shorthand if statements however am befuddled by why the expanded versions don't work quite the way I imagined they would.
Code 1 - Does not work
if(document.getElementById == true) {
alert("The document object model is supported by: " + navigator.appName);
}
Code 2 - Does work
if(document.getElementById != false) {
alert("The document object model is supported by: " + navigator.appName);
}
Code 3 - The shorthand that does work
if(document.getElementById) {
alert("The document object model is supported by: " + navigator.appName);
}
Why is that if I expand the shorthand in 3 to the first code sample not work and why does it work if I have it equal to != false?