1.Basic type values include: undefined, null, boolean, string, number
Basic types occupy large and small spaces in memory respectively. The value is stored in the stack space, and we access it through by value.
undefined: Declare an undefined variable (only one value).
null: null means It is prepared to save the object, but the value of the object has not yet been actually saved.
var car = null;
alert(typeof(car))
boolean: Boolean value has two values, one is true and one is false.
String: Used to represent a character sequence consisting of zero or more characters, that is, a string. Strings can be expressed using double quotes and single quotes.
Number: Used to represent integers and floating point values. There is also a special value called NAN.
Expand a little knowledge, the difference between null and undefined:
detection What comes out is 'object'
2.
Reference types include: objects, arrays, functions, etc.Object (object type): var obj = {name: "花Magnolia ", Age: 20, Sex:" Women "}
Alert (" Name "+Obj.name+" Age is "+...)
## value, you must allocate space for this value inheap memory
. Since the size of reference type values is not fixed (objects have many properties and methods, and properties and methods can be added dynamically), they cannot be saved in stack memory. But the memory address size is fixed, so the memory address can be saved in stack memory.In short: the stack memory stores basic data type values, and the heap memory stores reference type values. The address of a reference type value in memory is stored on the stack, which is what we often call an object reference (pointer). Look at the picture below: ##3. Type conversion
1. Number() Example: var num1 = “11”;var num1 = Number (num1);
var num2 = 12; var num3 = num1+num2;
alert(num3);//23
2, parseInt() function
Convert the string into a numerical value of integer type
Features: Direct viewing Whether it matches the numeric pattern, it ignores spaces in front of the string until it finds the first non-space character.
If the first character is not a numeric character or a negative sign, parseInt() will return NaN. ##3. parseFloat()
Convert a string to a floating point type value
4. toString()
All types except undefined and null Values all have their toString() method, which is to return the string representation of the object
5, string()
null returns null undefined returns undefined
6, Boolean ()
Convert any type of value to a Boolean value
The following values will be converted to false: false, "", 0, NaN, null, undefined
The rest Any value will be converted to true
The above is the detailed content of What are the JanaScript data types?. For more information, please follow other related articles on the PHP Chinese website!