To give an answer to the question "What is the difference between a value and a type?":
Think of a type as some kind of category and a value is a concrete instance in that category.
For example, we have the type String
and a concrete value would be "foo"
. There can be many different values of type String
, but there are only one possible value for the Null
and Undefined
types, which are null
and undefined
respectively.
Section 4.3 of the specification is most helpful IMO. Here you find for example the information about strings and the difference between value, type and object.
4.3.16 String value
primitive value that is a finite ordered sequence of zero or more 16-bit unsigned integer.
NOTE: A String value is a member of the String type. Each integer value in the sequence usually represents a single 16-bit unit of UTF-16 text. However, ECMAScript does not place any restrictions or requirements on the values except that they must be 16-bit unsigned integers.
4.3.17 String type
set of all possible String values.
4.3.18 String object
member of the Object type that is an instance of the standard built-in String
constructor.
NOTE: A String object is created by using the String
constructor in a new expression, supplying a String value as an argument. The resulting object has an internal property whose value is the String value. A String object can be coerced to a String value by calling the String constructor as a function (15.5.1).
It's similar for null
and undefined
, though they don't have equivalent objects. Why? For that you'd have to ask those who define that language ;)
If "everything is an object", then one would assume we have objects for all available values, yes?
A more correct statement would be "nearly everything is an object", primitive values are not objects obviously, but most of them have an object equivalent (which should actually not be used) and for the others we don't care. Fact is that JavaScript is mainly object oriented.
Where's my Infinity and NaN objects?
Infinity
and NaN
are values of type Number
, so you could create Number
objects, like so:
new Number(1/0) // Infinity
new Number("a") // NaN
but you rarely use Number
objects anyway.