Javascript (二):Primitive Datatype
Primitive(原生的) datatype stored in memory stack.It’s value is literally copied(字面值复制).Even if change the original(原始的) value,the copied value remians unchanged.
- string
- number
- boolean
- undefined
- null
When a primitive value is used as if it were an object created by a constructor, JavaScript converts it to an object in order to respond to the expression at hand,but then discards the object qualities and changes it back to a primitive value. In the code below, I take primitive values and showcase what happens when the values are treated like objects
var pstr = “123”; pstr.toString(); // pstr =>Object =>primitive
var pnum = 123;
pnum.toString();
// pnum =>Object =>primitive
var ostr = new String("123");
ostr.toString();
// ostr =>primitive
var onum = new Number(123);
onum.toString();
//onum =>primitive