Согласно http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf, JavaScript имеет 6 типов: undefined
, null
, boolean
, string
, number
и 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
Вопрос 1:
Почему null типа object
вместо null
?
Вопрос 2:
Что насчет функций?
var f = function() {};
console.log(typeof f); // <-- function
Переменная f
имеет тип function
. Почему он не указан в спецификации как отдельный тип?
Спасибо,