First, the data type
There are 5 basic data types in ECMAScript, undefined, null, Boolen, number, string, respectively. There is also a complex data type object. object is essentially composed of a set of unordered name-value pairs.
Second, typeof operator
Using an operator on a value may return one of the following strings:
- ' Undefined '----If this value is not defined;
- ' Boolen '----If this value is a Boolean value;
- ' String '----if this value is a string;
- ' Number '----If the value is numeric;
- ' Object '----If this value is an object or null;
- ' function '----If this value is a function.
typeof 2==number;
typeof Nan==number;
var message= ' SSS ';
typeof Message==string;
typeof Null==object;
Third, instanceof operator
result= variable instanceof constructor;result==true or false;
Person instanceof object//variable person is object?
numeric conversions
There are three functions that convert a non-numeric value to a value: Number (), parseint (), parsefloat (). parseint () is more commonly used when working with integers.
Convert to String
(1) Numeric, Boolean, object, and string values have a ToString () method, but the null and undefined values do not have this method.
var num=10;
Alert (num.tostring ()); "10"
Alert (num.tostring (2)); "1010"
(2) A string () can be called when the value is not known to be null or undefined;
var value1=10;
var value2=true;
var value3=null;
var value4;
Alert (String (value1)); "10"
Alert (String (value2)); "True"
Alert (String (VALUE3)); "NULL"
Alert (String (VALUE4)); "Undefuned"
Object type
An instance of object has the following properties and methods:
- Constructor: Holds the function that is used to create the current object.
- hasOwnProperty (PropertyName): Used to check whether a given property is in an instance of the current object (not in the round prototype of the current instance), where the property name of the parameter propername must be specified as a string.
- Ispropertyof (object): Used to check if an incoming object is a prototype of another object.
- propertyIsEnumerable (PropertyName): Used to check whether a given property can be enumerated using the For-in statement.
- toLocaleString (), toString (), ValueOf ().
JS data type