Put simplest condition first in if statements

Unless the later parameters are guarding against an invalid state
Merge pull request #1011 from nschonni/reorder-js-conditional

Put simplest condition first in if statements