I saw this in code today and I am kind shocked that it does not produce an error
if($('.MyClass'))
{
// do stuff here
}
So it is a jquery selector inside a if statement. According to firebug if the selector is not found it returns null. If it is found it returns the dom object.
So from what I can tell it always goes into the if statement but I am kind a more shocked that it does not error out.
If in C# you tried to just have an object or null in an if statement I don’t think it would compile.
I was expecting at least an error to show up in firebug.
It doesn’t error out because (I’m assuming, of course, that you mistyped your question and you have quotes around your class name like
if($('.MyClass'))):Is valid syntax in JavaScript (although it may not do what you expect it to do).
JavaScript will try to cast null to a boolean value. When that cast happens, JavaScript specifies that the cast should return
false.