Monday, 15 September 2014

javascript - Distinguish between number and object quickly -



javascript - Distinguish between number and object quickly -

i've got complex info construction in javascript composed out of numbers , containers (arrays in case). fastest and/or memory efficient way store , process this? there non-obvious, improve speed and/or memory-wise, illustration [ [ 1, 2], [3, 4] ] requires similar typeof distinguish between tree branches , leaves when scanning it? construction big 1000000 numbers.

i've set jsperf test evaluate methods of distinguishing between numbers , objects, , typeof seems fastest except in opera , ie:

http://jsperf.com/typeof-number-vs-object

try:

isnan(myvar)

returns true id myvar not number, false otherwise.

docs

although, apparently, function isn't exclusively bug-free... (see docs linked to)

javascript performance

No comments:

Post a Comment