HomeToolsAbout a20k

Primitive Types

Faster null check with integer inputs

With integer inputs, checking for null or zero value faster

// commonly used approach if(x != 0) { // ... } // faster approach using omit operation if(x) { // 0 is False // other is True }

Coerce to zero on integer expectation

Coercing non-zero falsy values to zero with OR. This works because the OR operator returns the value of the second operand when the first operand is falsy.

integerExpectation = nonZeroFalsyValue || 0;
© VincentVanKoh