Difference between if (var.length >0){} and if (var){}

Viewed 31714

In javascript is there a difference between using

if (foo.length > 0) {
//run code involving foo
}

and

if (foo) {
//run code involving foo
}

If so, could someone please explain the difference and an example where they would not be the same?

4 Answers
Related