The Boxing Day entry is all about testing argument types in functions. JavaScript does not allow you to specify types of function arguments. If you want to know what has been passed into a function, you’ll need to test it.
Type | Test |
---|---|
String | typeof x === 'string' || x instanceof String |
Regex | x instanceof RegExp |
Number | typeof x === 'number' || x instanceof Number |
Convertible to Number | typeof +x === 'number' |
Array | Array.isArray(x) |
Function | typeof x === 'function' |
Use them in good health.