Why does typeOf return object instead of array in array data type? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why does typeOf return object instead of array in array data type?

17th Jul 2020, 12:13 PM
Anyanwu Johnbosco Chima
Anyanwu Johnbosco Chima - avatar
2 Answers
+ 2
Because Array extends Object prototype Try this in a console or REPL Array.prototype.__proto__ === Object.prototype It outputs 'true' So based on laws of inheritance an Array *IS AN* Object As an FYI, typeof can only return six possible results: object, function, string, number, boolean and undefined. Everything else in JavaScript extends from these base prototypes.
17th Jul 2020, 2:09 PM
Ore
Ore - avatar
+ 1
Explained in my video: https://youtu.be/y-LnKLCTgw4
17th Jul 2020, 1:39 PM
Gordon
Gordon - avatar