4

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?

4
  • That list is essentially meaningless. Arrays are regular objects. Commented Oct 13, 2014 at 16:22
  • 4
    "datatype" isn't even a term used by the JavaScript spec. Commented Oct 13, 2014 at 16:24
  • typeof is special and doesn't actually return the type of the value (according to the spec). It's just a lookup table: ecma-international.org/ecma-262/5.1/#sec-11.4.3 Commented Oct 13, 2014 at 16:46
  • Function is as much a data type as Array is. Commented Oct 17, 2014 at 5:39

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Are you saying typeof { Call: function(){ } } should return function?
@Luizgrs ecma-international.org/ecma-262/5.1/#sec-13.2.1 - [[Call]] is an internal property
with the specs it's now clear, I thought that brackets meant something but I couldn't understand, now it's fine..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.