Search code examples
javascriptfunctionobjecttypeof

What is the correct typeof a JavaScript function?


Most people know that all functions in JavaScript are actually objects, but why is it that typeof function() {} returns function instead of object? By this logic, why does typeof [] not return array?

Is this just a 'standard' that is followed or is there a valid reason?


Solution

  • Because that's what the spec says.

    typeof returns primitive types only; all regular objects are reported as "object".