the `typeof` check was recommended on stackoverflow for some edge case