Do not call str.length if str is undefined