On 2/23/16 6:30 PM, Peter Thatcher wrote:
> My opinion: B is better than A. I have no sympathy for someone
> calling foo(bar) and expecting it to be the same as foo(bar, false).
> This is JS, which does all kinds of bizarre things with
> undefined/false values, and that's just asking for pain. For example,
> what if foo() does addition?
And I have no sympathy for someone doing boolean addition.
> function foo(bar, baz) {
> return bar + baz;
> }
>
> foo("bar") // "barundefined"
> foo("bar", false) // "barfalse"
> foo(1, undefined) // NaN
> foo(1, false) // 1
>
> Not the same!
Lets return from WAT!-land and use booleans correctly, in conditions:
function foo(bar, baz) {
return baz ? bar : null;
}
foo("bar") // null
foo("bar", false) // null
foo(1, undefined) // null
foo(1, false) // null
.: Jan-Ivar :.