In the example involving regular objects that you provided there is little difference. However, another typical pattern can be:
var radioButtons = document.forms['formName'].elements['radioButtonName'];
if ('undefined' === typeof radioButtons.length) {
radioButtons = [ radioButtons ];
}
for (var i = 0; i < radioButtons.length; i++) {
// ...
}
If you used if (!radioButtons.length)
it would evaluate true when no radio buttons were found (radioButtons.length is 0) and create an array of a single (non-existent) radio button. The same problem can arise if you choose to handle the radio buttons using:
if ('undefined' === typeof radioButtons.length) {
// there is only one
} else {
// there are many or none
}
There are other examples involving empty strings where if (!variable)
is probably not recommended and it is better to test against typeof undefined or explicitly test against null.