Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 507
Maximus S Avatar asked Sep 30 '22 15:09

Maximus S


1 Answers

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.

like image 184
Prabhu Murthy Avatar answered Oct 03 '22 01:10

Prabhu Murthy