FYI with instanceof you don't need a separate check for bool/object. It doesn't throw errors.