JavaScript data types

Source: Internet
Author: User

One, basic data type: number string Boolean NaN undefind

Reference data type: (Object data type) object (function data type) function

Number: Positive, negative, 0
NaN: is not equal;
=/is the meaning of assignment;
==/is to judge whether the values of the left and right sides are equal;
/isnan () detects whether a value is valid for a proposition that is invalid for ture valid for false
parseint ()//force rounding conversion left-to-right rounding does not recognize the decimal point
Parsefloat ()//Force rounding Decimal

Boolean:ture false
An exclamation point is the inverse of the value. First, convert the values to Boolean in the inverse
!! The effect of two exclamation marks is to convert other data types to Boolean values to take the inverse two times equivalent to
Object = = object//Never equal
Object = = string//First convert the object to a string and then compare (call the ToString method) to compare
Example:
[1,2,3,4,5]= "";
[1,2,3,4,5].tostring ()//"1,2,3,4,5" is not equal to an empty string ""

Second, the data type conversion rules
1>null ==undefined/ture but null,undefined and other book types are not equal;

2> Number = = Boolean//Boolean required to convert to a number

3> Number = = string string converted to a number

4> If there is only one value to determine whether this value is true or FALSE, follow: only 0,nan "" Null undefined
These five are fake, the rest are true.

Object: Reference data type (object data type)

Object data type in JS data type

There are several sets of [attribute name and attribute value], which consists of multiple sets of key-value pairs, with multiple key:value
Property names and property values are used to describe the characteristics of this object.
var obj ={name: "Zhufeng", age:6};
var personinfo ={
Name: "Zhang San",
Age:28,
Height: "180cm",
Weight: "60kg"
}

var obj ={name: "Zhang"};//literal creation method can be seen visually

var obj =object ();//Instance Creation object

Adds a set of property names and property values to an object
Obj.name = "Zhang";
obj["Name"]= "Zhang";

Gets the property name and property value, if the property name does not exist, the result returned by default is undefined
Console.log (obj["name"]);
Console.log (Obj.name);
Console.log (OBJ.ZZ);//No obj.zz attribute value so undefined

Delete property names and property values
false delete obj.age = null;
Delete delete Obj.age is true;
Console.log (obj);

Object data type, can also be specific subdivision;
Objects (object), Array (arr), Regular (REGEXP), Time (date), Strings (String) Boolean
var obj ={};
var arr =[];
var reg =/$/;

JS objects, classes, instances of the difference: the object is a generic: JS in everything objects, class is the specific subdivision of the object,
An instance is a specific thing in a class, and everything is Object


Three, the difference between the basic data type and the reference data type
var num1 = 12;
var num2 = NUM1; The value represented by the NUM1 variable is given to the NUM2 variable
num++//self-increment 1 own plus 1 can also be written num+=1

Detection of data types
The typeof operator returns a string regardless of what data type is detected

JavaScript data types

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.