Why is a “function” not considered as a data type in javascript?

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

Why is this so, and what is the definition of a data type?

+4
source share
1 answer

Functions are just objects in JavaScript. But the difference lies in the internal property [[Call]]that distinguishes them from ordinary objects. When typeofused against an object, and if it finds a property [[Call]], it returns a String function.

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

+3

All Articles