Use defined() instead of typeof for checking undefined.