Hi,
As per http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf,
JavaScript has 6 types: undefined
, null
, boolean
, string
, number
and object
.
var und;
console.log(typeof und); // <-- undefined
var n = null;
console.log(typeof n); // <--- **object**!
var b = true;
console.log(typeof b); // <-- boolean
var str = "myString"
console.log(typeof str); // <-- string
var int = 10;
console.log(typeof int); // <-- number
var obj = {}
console.log(typeof obj); // <-- object
Question 1:
Why is null of type object
instead of null
?
Question 2:
What about functions?
var f = function() {};
console.log(typeof f); // <-- function
Variable f
has type of function
. Why isn't it specified in the specification
as a separate type?
Thanks,