Typo
Corrected minor error in sample code
Use typeof operator for undefined checking