2 ms·
In general I would validate for the thing I'm actually looking for instead of validating against undefined and other invalid input values. For example: fun
by dheera 6y ago
In general I would validate for the thing I'm actually looking for instead of validating against undefined and other invalid input values. For example:
function setContrast(value) {
if(typeof(value) !== "number") throw "input must be a number";
if(!(value >= 0 && value <= 1)) throw "input must be between 0 and 1 inclusive";
// ... rest of code ...
}
This pattern will generally avoid any issues with undefined values being passed in.