JavaScript types

Posted by Alex Ivasyuv on Stack Overflow See other posts from Stack Overflow or by Alex Ivasyuv
Published on 2010-03-25T18:20:02Z Indexed on 2010/03/25 18:23 UTC
Read the original article Hit count: 467

Filed under:
|
|

Hi,

as per http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf
JavaScript has 6 types: 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

Question 1:

Why null is object type, if it has to be a null type.

Question 2:

What about function?

var f = function() {};
console.log(typeof f); // <-- function

Variable f has "function" type. Why it doesn't specified in specification as separate type.

Thanks,

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about ecmascript