fixed typeof bug, L48

fixed typeof bug on line 48: typeof val, replaced with: typeof val === 'undefined'

globally: replaced typeof != 'undefined' with != null

note: typeof val == 'undefined' should be replaced with typeof val === 'undefined'

if you really care to detect undefined then the code is mostly correct, but null maybe find its way in there as representing undefined.  this can happen when array or object elements are removed using assignment of null;

unless I am not fully understanding the intention bettter to use simply val != null, which handles both undefined and null values.