I was taking a look at some node.js code earlier, and I noticed that the guy who wrote it seemed to favour the following syntax:
var fn = function (param) {
var paramWithDefault = null == param ? 'Default Value' : param;
}
Over what I consider to be the more concise:
var fn = function (param) {
var paramWithDefault = param || 'Default Value';
}
I was wondering if the second form is actually more socially acceptable JavaScript syntax, I've seen it out in the wild more times than the ternary operator for this purpose.
I note that in the first example he's using the double equals (not the triple equals) which means it will count "undefined" as null, which would reduce one impact that I could think of. However, I've read in numerous places that == is a rather evil operator in JavaScript (JSLint is very much against it, IIRC).