简体   繁体   中英

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?

Because that's what the spec says.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM