JavaScript: Advanced typeOf