Using &&'s short-circuiting as an if statement?

Yes, your two examples are equivalent. It works like this in pretty much all languages, but it's become rather idiomatic in Javascript. Personally I think it's good in some situations but can be abused in others. It's definitely shorter though, which can be important to minimize Javascript load times.

Also see Can somebody explain how John Resig's pretty.js JavaScript works?


It's standard, but neither JSLint nor JSHint like it:

Expected an assignment or function call and instead saw an expression.