Typeof array is an object in javascript

Marco Pestrin
Dec 8, 2020

Often there is a need to compare variable types in javascript

The result is

Apparently there seems to be something wrong because the array is recognized as an object and seems to be no real difference between object and array.

This because in javascript all derived data type is always a type object. Included functions and array.

In case you need to check if it’s an array you can use isArray method of Array.

The result is

otherwise there is a instanceOf operator

and the result will be the same as the previous one.

--

--