change undefined to typeof to avoid reference error

prevents reference error