JavaScript Cold knowledge

Source: Internet
Author: User

The 1.+ number (unary plus operator), if placed before the value, will not have any effect on the value, but put in front of the other, it is equal to call number () to convert him to a digit, the Boolean value false is converted to 0,ture is converted to 1

For example, + "1.1" = 1.1, the object calls its valueof () or ToString () function, and then to the value

2.parseInt can be used to specify the type of data, such as parseint ("12", 8)//10 The second parameter is a binary

Parsefloat has only one parameter and can only be converted to decimal

31-Dollar subtraction operator: the same principle as the + sign, but it turns to the opposite number.

4 ToString Operation: You can use it to convert a value to a different binary

Ex:var i = 10; i.ToString (+)//' a '

5 >> (right Shift) and << (left shift) do not change the sign bit, but >>> will move with the sign bit

6 logic or operator | | The operand is returned, not true or false.

Ex:var a = "Test" var b = A | | c//b = "Test"

var b = null | | A//b = "Test"

7 adding a number to a string equals the value added to the string

var result = "5" + 5; result = "55"

If you subtract a number from a string, the string is converted to a number to be calculated.

var result = 5-"1"//result = 4

8. < comparator

Therefore, 2 < "3"//True "3" > "+"//True

However, any results that are compared to Nan return false, such as ' a ' >///False ' a ' <=//False

9.with statement: Set the scope of your code to a specific object, such as

var PS = Location.search

var hostName = Location.hostname

var url = location.href

We can change to:

With (location) {

var PS = Search

var hostName = HostName

var url = href

}

10.javascript has no overloaded functions. The previous function will be overwritten by the last one.

You can use Arguments.length to get the number of input parameters, Arguments[i] to get the I parameter

11. When assigning a value, if the assignment of the base type is equal to the creation of a new value, and if the assignment of the reference type (object), two points to the same object

var i = 5; var B = i; i = 4//i = 4, B = 5

var obj1 = new Object (); Obj2 = obj1; obj1.t = "ASD"; obj2.t//"ASD"

The same is true for function arguments, where the base type is equal to the creation of a new value, the reference type points to the same object, but is passed by value, except that it points to the same address, and if he equals a new object inside the function, the outside is unaffected.

12 use instance to determine what type of object is the//array, you can use the Array.isarray (value) method to determine

  

13.javascript has no block-level scope, so

if (i = 1) {var result = "Test"} console.log (Result)//"Test"

A function can be used to solve this problem, local variables defined inside the function, external access to the

14. When accessing the properties of an object, you can pass. or [], for example

var i = {name: "Test"} i.name = = i["Name"]

The square brackets method is used if the property name includes a character that causes a syntax error or if the property name uses a keyword or a reserved word. person[' First name '] = ' cjg '//Not available.

Array.Sort (): The function converts each item of an array into a string and then compares it, which causes a problem: var values = [0,1,5,10,15] Values.sort (); 0, 1, 10, 15, 5

Workaround: It can accept a function parameter, so we can write a comparison function by ourselves:

Function cmp (value1, value2) {return value2-value1;}

Then Values.sort (CMP)//0, 1, 5, 10, 15

So we can decide how it's sorted

16 Common operations for arrays:

Concat: Creates a new array based on the contents of the current array

var i = [+/-]

var B = i.concat[4,[6,8]]//[1,2,3,4,6,8]

Slice: Creates a new array based on one or more items of the current array

var i = [1,2,3,4]

var b= i.slice (1)//[2,3,4]

var c = i.slice (1,3)//[2,3]

Splice: Used to delete data (the first two parameters, the location of deleted items, and the number of deletions) or insert data (three parameters, starting position, 0, and the item to be inserted) or replace (three parameters, starting position, 1, any number of items to insert)

var i = [1,2,3,4]

var B = i.splice (0,1)//b = [1] i = [2,3,4]

JavaScript Cold knowledge

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.