JavaScript data types and conversions

Source: Internet
Author: User

JavaScript data Types

1.Boolean(Boolean)

Boolean: (value type) var b1=true;//boolean type

2. number (numeric) Value : (value type) var n1=3.1415926;//numeric type n1.tofixed (3);//rounding retains 3 decimal places. 3 . String
var s1= ' hello ';//String Type
String: (value type, string immutable attribute) 4. Undefined (not defined) 
undefined is a value type, and the result computed with other values is not what we want, but slightly different from the null in the database, such as with numeric calculations or with string calculations.
The undefined type, the null type, are data types with only one value, undefined and null, respectively. 5. Null (Empty object)
6.Object (object type) object is a reference type, others are basic data types .
String is also a base type and cannot be added to a dynamic property, while a reference type is available. A reference type Object instanceof type that determines whether a value is a type, all reference types Instanceof object returns are true 7. Application Type
Object: (reference type) var tim=new Date ();//object Type (object) var names=[' Zs ', ' ls ', ' ww '];//array is also object type (object) var obj=null;// Object function: (reference type) function fun () {}//typeof (fun);//output is function, function type PS: View variable type with typeof (variable)

null and undefined in JavaScript

Undefined, which indicates an unknown state

If the variable is declared but not initialized, the value of the variable is an unknown state (undefined). The return value is a undefined when there is no explicit return value (access to a nonexistent property or an object Window.xxx) method. When the typeof operator is applied to an undeclared variable, it is displayed as undefined (*)

Null represents an object that does not already exist, and Null is a value that has a special meaning.

A variable can be assigned a value of NULL, when the value of the variable is "known state" (not undefined), or null. (Used to initialize variables, clear variable contents, free memory)

Undefined==null//The 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 = = Converts a value to a type and then determines whether it is equal, sometimes with unexpected results, it is recommended to use = = =. But note that there are cases where using = = can bring better results.

Type Conversions

parseint (ARG) converts the specified string to an integer

Parsefloat (ARG) converts the specified string into a floating-point number

Number (ARG) converts the given value (any type) to a digit (which can be an integer or a floating point), and the entire value, not the partial value, is converted. If the string cannot be fully converted to an integral type, Nan is returned. (Not a number)

IsNaN (ARG), determines 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 the given value (any type) to a Boolean type;

(*) eval (codestring) computes and executes a string of JS code.


JavaScript data types and conversions

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.