What is the difference between (null != someVariable) and (someVariable != null)? I have seen a lot of people using 'null' first in the comparison. Which one is better than the other and why?
However, the first one will cause an invalid assignment error if you mistype
=. Some people like this as it's rather easy to type
= instead of
==, although the former isn't always an accident.
You can see the precise rules of the specification with regard to the
== operator on the Annotated ES5.
They evaluate to the same thing, but it is preferable to choose
(someVariable != null), because the other way is a Yoda condition. It deals with readability.
The first might be better of
someVariable is actually a function with a very long list of arguments. Your intention would be easier to see at first glance. Otherwise, I always use the second.