What JavaScript must Know (ii)

Source: Internet
Author: User
Tags array length

  The article does not elaborate on the specific contents of the various points of knowledge, only the main points listed, for everyone to learn the time reference, or to detect whether they are proficient in JavaScript, clear the contents of the various parts.

The built-in object can be divided into Data encapsulation class object, tool class object, error class object, as follows.

Data Encapsulation Class object:

    1. Number Object
    2. String Object
    3. Boolean Object
    4. Array Object
    5. Object
    6. Function

Tool Class object:

    1. Math Object
    2. Date Object
    3. RegExp Object

Error class object:

    1. Error Object

Number Object  

JavaScript has only one numeric type. Number, including positive and negative integers, plus and minus decimals, octal numbers, hexadecimal numbers, nan,infinity,-infinity.

  Infinity: Infinity, a positive number exceeds the upper limit (overflow) that JavaScript can represent.

-Infinity: infinity, negative numbers exceed the range of negative numbers that JavaScript can represent.

NaN: A special value for a non-numeric value. This property is used to indicate that a value is not a number.

The number can be a number or an object . To differentiate :var x=123; var y = new number (123); (x===y)//false

Each number occupies 8Byte of storage space.

If the prefix is 0, JavaScript interprets numeric constants as octal numbers, and if the prefixes are 0 and "X", they are interpreted as hexadecimal numbers.

Floating point accuracy problem:(0.2+0.1)! = 0.3

  All programming languages are difficult to determine the accuracy of floating-point data: Var x=0.1,y=0.2; var z=x+y; if (z==0.3)//return False

Solved by the multiplication method of integer:var z = (x * + y *)/ten;//z is 0.3

  ToString () method: var mynumber = 128;

Mynumber.tostring ();//Turn to 10 binary string, output 128.

          Mynumber.tostring (2); //Turn into 2 binary string, output 10000000.

          Mynumber.tostring (8); //Turn into 8 binary strings, output.

Mynumber.tostring (16); //Turn into 16 string, output.

Number () method: var str = "123"; Alert (number (str));//convert string to digital, output 123.

IsNaN () Method: Determines whether a value is a NaN value.

var x = +/"Apple"; IsNaN (x); is not a numeric value, returns True

var var x = 1000/0;  IsNaN (x); is a numeric value that returns false

ValueOf () Method: Returns the base numeric value of a number object.

ToFixed () Method: Converts a number to a string, the result of which has a specified number of digits after the decimal point.

Toprecision () Method: Formats the number as the specified length.

String Object

  differentiate: var str = " hello "; var str = new Stri ng ("Hello");

  Length Property:

CharAt (): Returns the character at the specified position.

IndexOf (): Returns the position of the first occurrence of a specified string value in the string, and no return-1 is found.

  concat (): Joins two or more strings and returns a new string.

Split (): Splits a string into an array of strings.

  Slice (): Extracts a fragment of a string and returns the extracted part in a new string.

lastIndexOf (), Match (), replace (), search (),substr (), substring (), trim (), toLowerCase (), toUpperCase (), ValueOf ()

Boolean Object

  A Boolean (Boolean) object is used to convert a non-Boolean value to a Boolean value (True or false).

Boolean ();

  If the Boolean object has no initial value or its value is: 0,-0, NULL, "", false, Undefined, NaN. Then the value of the object is false.

Otherwise, its value is true, even when the value of the variable is the string "false"!

ToString ();

ValueOf (); Returns the original value of the Boolean object.

Array Object  

Join (); Put all the elements of the array into a string.

Shift (); deletes and returns the first element of the array.

Unshift (); adds one or more elements to the beginning of the array and returns the new array length.

Pop (); deletes and returns the last element of the array.

Push (); adds one or more elements to the end of the array and returns the new array length.

Concat (), joins two or more arrays, and returns the result.

Slice (); Select part of the array and return the new array.

Splice (); Add or remove elements from the array.

Reverse (); Reverses the element order of the array.

Sort ();

ToString ();

ValueOf ();

Object

  ...

Function  

...

Math  

...

Date  

The Date object is used to process dates and times.

Regexp

  The regular expression.

Error

  ...

What JavaScript must Know (ii)

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.