JavaScript's understanding Record

Source: Internet
Author: User

1, JavaScript data types are divided into two categories: primitive type and object type;

Primitive types include: numbers, strings, Booleans, nulls, and undefined; (All immutable types, values cannot be modified)

Object types: Ordinary objects and functions;

Functions can use new to create new objects, i.e. constructors; each constructor defines a class of objects-a collection of objects initialized by constructors;

A class can be considered a subtype of an object type, and the classes defined by the JavaScript language are mainly: array of arrays, function functions, date dates

The regular Regexp:var pattern=/s$/is equivalent to var pattern = new RegExp ("S $") and is used to match any string ending with ' s ';

Err Error: Defines an object that represents the error and syntax errors that are run in the program, and is used in Try--catch.

--------------------------------------------

Examples of common type judgments:

Define variables: var n;

Assign a value-----

Get type: typeof N

' Undefined '---this value is undefined;
' Boolean '---This value is a Boolean value;
' String '---This value is a string;
' Number '---this value is numeric;
' Object '---This value is an object or null;
The value of ' function '---is a function.

Null and functions are also objects, but return values are different;

---------------------------------------------

2. Numeric type:

1), all numbers are represented by floating-point numbers;

2), JavaScript predefined global Variables nan non-numeric value and infinity positive infinity;

X!=x is true only if X is Nan, and the others are false;

The IsNaN () return value is true only if the parameter is a Nan or a non-numeric value;

Isfinite () returns true only if the parameter is not Nan, infinity, or-infinity;

3), JavaScript floating-point notation is a binary notation, can not accurately represent a number similar to 0.1;

var x = 0.3-0.2; var y = 0.2-0.1;alert (x = = y); False

JavaScript in real running environment: x=0.099 999 999 999 999 98 y = 0.1;

3, string, the use of the regular example:

var text = "test:1,2,3";

var pattern =/\d+/g//Matches all instances that contain one or more numbers;

Pattern.test (text); True match succeeded;

Text.search (pattern); 6 first match success position;

Text.match (pattern); [All-in-all] an array of successful matches;

Text.replace (Pattern, ' # '); [test:#,#,#] Replace

4. Boolean value:

When judging the following values: Undefined,null,0,-0,nan, "" are false;

var y; var x= null; Alert (x = = y);//True y is undefined;

5. Type conversion:

1.number-to-string:

var n = 123456.789;

N.tofixed (2)//123456.78 specifies the number of digits after the decimal point;

N.toexponential (2)//1.23e+5 Specify the exponential counting method, the decimal money is fixed one place;

N.toprecision (10)//123456.7890 Specify a valid number of digits

N.toprecision (2)//1.23e+5 if it is less than the whole number of digits, it is converted to exponential

2.string-to-number:

parseint ()//parse integer;

Parsefloat ()//parse integers and floating-point numbers;

6, Function: function variable declaration in advance

var n = ' global ';

function () {

Console.log (n); Undefined

var n = ' scope ';

Console.log (n); Scope

}

Equivalent to:

var n = ' global ';

function () {

var n;

Console.log (n); Undefined

n = ' scope ';

Console.log (n); Scope

}

JavaScript's understanding Record

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.