The MDN said :
Six data types that are primitives:
- Boolean
- Null
- Undefined
- Number
- String
Symbol (new in ECMAScript 6)
and Object
But I confused, the function data type and object data type.
Let's see :
var func = function() {
console.log ('Hello World ! ')
};
var obj = {
property : something
}
console.log(typeof(func)); // ===> function
console.log(typeof(obj)); // ===> object
Is it different function data type and object data type? Why typeof(func) is function? not a object? The document said there are 7 data type (6 primitive, 1 object). function is not include anywhere.
Until now, over 1 year, I think function's data type is object, I heard the function is first class object in JavaScript, so I don't have doubt about function is object but today I think more time, and wondered.
Is it different?
typeofdoesn't return the Data Type.typeofdoesn't report the value's true data type. It's a lookup table that maps data type and other value characteristics to a name: ecma-international.org/ecma-262/6.0/… . Functions are objects that have an internal[[Call]]property. That's whytypeof nullis"object"(*grumpy face*).typeof nullto"object"is historical