Your code doesn't check that
a is
null. It's possible to assign certain values to
a so that your condition will evaluate to true anyway, the most obvious of which you have demonstrated yourself by assigning the empty
string to
a.
There are three approaches you can take, depending on what
a represents and what you want your application to do with it:
1) Check that
a is
exactly null:
if (a === null) {
2) Check that
a is
similar to
null:
if (a == null) {
3) Check that
a is
falsey:
if (!a) {
The most common approach is the third.