The typeof null and isObject() short story

null is a primitive but typeof(null) return “object”


In short: it is bug in ECMAScript, and the type should be null. This is a official mistake in the language, carefully kept from 90’s for compatibility.


How we can fix this issue?

What we can implement is a better typeof:
Do a typeof to prevent the app from executing input that is not a valid function at all.


The native can help us to validate Arrays: Array.isArray() method returns true if an object is an array, false if it is not.

Angular 1.*
Angular implement few fix for this issue:

AJS 1.2.9 Vs. 1.3.2 isObject()

AJS 1.3.2+

AJS 1.2.9

Benchmark results

The 1.3.2 is ~1.25 faster than the previous one (this is mainly based on the == and === behaviour)


Leave a Reply

Your email address will not be published. Required fields are marked *

* Copy This Password *

* Type Or Paste Password Here *