JavaScript data type
1.Boolean (Boolean)
Boolean: (value type) var b1=true;//boolean type
2.Number (digital)
Numeric value: (value type) var n1=3.1415926;//numeric type
N1.tofixed (3);//rounded to keep 3 decimal digits.
3.String (String)
Copy Code code as follows:
var s1= ' hello ';//String type
String: (value type, string immutable attribute)
4.Undefined (not defined)
Undefined belong to a value type, and other values are calculated with a result that is not what we want, but is slightly different from the null in the database, such as calculations with numbers or with a string.
The undefined type, the null type, is a data type with only one value, undefined and null, respectively.
5.Null (Empty object)
6.Object (Object type)
object is a reference type, and all others are basic data types.
String is also a basic type, and you cannot add dynamic properties to string, while referencing types can be.
Reference type Object instanceof type, determine if a value is a type, all reference types instanceof object return True
7. Application Type
Objects (object): (reference type)
Copy Code code as follows:
var tim=new Date ();//Object type
var names=[' Zs ', ' ls ', ' ww '];//array is also an object type
var obj=null;//object
Functions: (Reference type)
Copy Code code as follows:
function Fun () {}//typeof (fun);//The output result is a function, type
PS: View the type of variable with typeof (variable)
Null and undefined in JavaScript
Undefined, representing an unknown state
The variable is declared but not initialized, and the value of the variable is an unknown state (undefined). (Accessing a nonexistent property or object Window.xxx) method does not explicitly return a value, the return value is a undefined. When the typeof operator is applied to an undeclared variable, it is displayed as undefined (*)
Null represents an object that does not exist, and Null is a value of special significance.
You can assign a value of NULL to a variable, at which point the value of the variable is known (not undefined), or null. (Used to initialize variables, clear variable contents, free memory)
Undefined==null//result is true, but the meaning is different.
Undefined===null//false (*), PS: First determine whether the type is consistent, and then determine the value. = = = Strictly equal To,!== strictly not equal to
because = = will be converted to the value of the type after the equality, sometimes may have unexpected results, so the recommended use = = =. But note that some situations using = = can bring better results.
Type conversions
Copy Code code as follows:
parseint (ARG) converts the specified string to an integer
Parsefloat (ARG) converts the specified string to a floating-point number
Number (ARG) converts the given value (any type) to numbers (which can be integers or floats) and converts the entire value, not the partial value. Returns Nan if the string cannot be completely converted to an integral type. (Not a number)
isNaN (ARG) to determine whether Arg is a non-numeric (Nan), and Nan is not equal to Nan.
String (ARG) converts the given value (any type) to a string;
Boolean (ARG) converts a given value (any type) to a Boolean;
(*) eval (codestring) computes and executes the JS code of a string.
The above is the JavaScript data types and conversion methods, I hope you can enjoy.