JavaScript data types
1.Boolean
Boolean: (value type) var b1=true;//Boolean type
2.Number (number)
Numerical value: (value type) var n1=3.1415926;//Numeric type
n1.toFixed(3);//Round to 3 decimal places.
3.String (string)
String: (value type, immutable character of string)
4.Undefined
undefined belongs to the value type, and the result obtained by calculation with other values is not what we want, but it is slightly different from null in the database, such as the result of calculation with numbers or calculation with strings.
Undefined type and Null type are data types with only one value, respectively undefined and null.
5.Null (empty object)
6.Object (object type)
Object is a reference type, and others are basic data types.
String is also a basic type. You cannot add dynamic attributes to String, but you can add reference types.
Reference type object instanceof type is used to determine whether a certain value is of a certain type. All reference types instanceof Object returns true
7.Application Type
Object: (reference type)
Function: (reference type)
PS: To check the type of a variable, use typeof(variable)
Null and undefined in JavaScript
undefined, indicating an unknown state
If the variable is declared but not initialized, the value of the variable is in an unknown state (undefined). (Accessing non-existent properties or objects window.xxx) When the method does not explicitly return a value, the return value is an undefined. When the typeof operator is applied to an undeclared variable, it is displayed as undefined (*)
null represents an object that does not yet exist. null is a value with special meaning.
You can assign null to a variable. At this time, the value of the variable is "known state" (not undefined), that is, null. (Used to initialize variables, clear variable contents, and release memory)
undefined==null //The result is true, but the meaning is different.
undefined===null //false(*),PS: First determine whether the types are consistent, and then determine the value. ===Strictly equal,!==Strictly not equal
Because == will convert the value type before judging whether it is equal, sometimes there may be unexpected results, so it is recommended to use ===. But note that in some cases using == can bring better results.
Type conversion
The above is the data type and conversion method of JavaScript. I hope you will like it.