Maximus S
Maximus S

Reputation: 11095

why isn't "function" considered a datatype in javascript?

The datatypes listed in MSDN for javascript are Number, String, Boolean, Object, Array, Null, Undefined. However, when you do typeof function, its type is function.

Why is this the case, and what's the definition of datatype?

Upvotes: 4

Views: 218

Answers (1)

Prabhu Murthy
Prabhu Murthy

Reputation: 9261

Functions are just Objects in JavaScript. But the difference lies in an internal property called [[Call]] that differentiates them from normal Objects. When typeof is used against an Object, and if it finds the [[Call]] property, then it returns the String "function".

This behavior can be found in the ECMA Specification for typeof.

Upvotes: 3

Related Questions