use typeof to check if the variable is defined or not to avoid exception