javascript - Are these statements functionally equivalent? -
as far can tell function same, wanted create sure. utilize latter statement less code , seems more efficient.
function updaterunningtotals(taxexempt, disctype, discamt){ if (typeof taxexempt === 'undefined') { taxexempt = false; } taxexempt = taxexempt || false; }
i have been using if
, have seen latter statement in open source projects. same thing? performance benefit?
edit: taxexempt, in scenario may not passed in.
> if (typeof taxexempt === 'undefined') { taxexempt = false; }
in case, textexempt set false if value undefined.
> taxexempt = taxexempt || false;
in case, taxexempt set false if value coerces false (i.e. toboolean(taxexempt) returns false), e.g. might null, 0, false, nan, '' or undefined.
so no, not functionally equivalent. , choosing sec because it's less code not sound logic. first clearer logic most.
javascript
No comments:
Post a Comment