Generic function to check null or undefined