Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

typeof (Array, null) returns object and typeof(null, Array) returns function

Tags:

javascript

As the title says it all, typeof (Array, null) returns object and typeof(null, Array) returns function.

It returns the type of the second parameter.

Why ?

like image 802
Om3ga Avatar asked Sep 01 '13 09:09

Om3ga


1 Answers

Because

  • typeof is an operator, not a function, so typeof(expr) is typeof expr, with expr evaluated first
  • a,b returns b

So

typeof (a, b) returns typeof b

and in your case

  • typeof (Array, null) is typeof null which is "object"
  • typeof(null, Array) is typeof Array, and Array is a function.
like image 160
Denys Séguret Avatar answered Sep 18 '22 17:09

Denys Séguret