use typeof when checking for undefined