Bulletproof type checks in JavaScript