Check variable type before calling toUpperCase()