JavaScript Knowledge Collation

Source: Internet
Author: User
Tags javascript array hasownproperty

I. Types and variables

1. The data types in JS are divided into two categories: primitive type and object type. Primitive types include numbers, strings, and Boolean values

2. An object is a collection of properties, each of which is composed of key-value pairs.

3. A string is an array of characters, and it is immutable

4. In any programming language that uses binary floating-point numbers, you will encounter floating-point accuracy problems. Use large integers for important calculations to reduce errors (smaller units)

5. Two date objects can be added and subtracted to calculate the time

6. Numbers and strings are not objects, but they have methods. The reason is that when their method is called, new String/number is automatically executed to generate a temporary object. When the reference ends, the temporary object is destroyed

7. If you want to make an object/array copy, you must explicitly copy each property of the object or each element of the array. Similarly, if you want to compare two separate objects or arrays, you need to do the same

8. There is no block-level scope in JS (until ES 5), only function scope and global scope

9. In the function, the declaration of the variable is advanced to the top of the function, but the initialization is still in its original position. This is called "declaration in advance."

10. When declaring a global variable, you are actually defining a property of the global object, so you can use delete to delete them

11. When a function is defined, a scope chain is actually saved. When this function is called, it creates a new object to store its local variables and adds the object to the saved scope chain. A colleague creates a new long "chain" that represents the scope of a function call

Ii. Expressions and operators

1. Strict equality operator "= = =" First calculates the value of its operand, the comparison process does not have any type conversion

2. Nan is not equal to any of the means, including its own

3. The instanceof operator expects an object on the left and a class that identifies the object on the right. Returns True if the left object is an instance of the right class

4. Eval () has only one parameter, if the passed argument is not a string, it returns the parameter directly, and if the argument is a string, it compiles the string as a JS code. If the compilation succeeds, start executing the code and return the value of the last expression or statement in the string

5. typeof is placed before a single operand, and the operand can be of any type. Returns a String representing the type of operand

6. Delete is a unary operator used to delete an object's properties or elements of an array

Third, the statement

1. The use of var name = function and functions declared directly using function is a little different, the function that uses the declaration statement is defined in advance, regardless of function definition or function body, it is visible to the whole scope. Functions that are declared with a function definition expression are only declared in advance (consistent with the VAR declaration variable)

2. The expression at the back of switch is compared using "= = ="

3. When an exception is thrown, the JavaScript interpreter immediately stops the currently executing logic and jumps to the nearest exception handler. If the function that throws the exception does not have an exception handler, the exception propagates upward along the lexical structure and call stack of the JavaScript method. If no exception handler is found, JavaScript will treat the exception as an error and report it to the user.

4. With object is used to extend the scope chain, in most cases should not use

Iv. objects

1. All values in JavaScript are objects except strings, numbers, true, false, NULL, and undefined

2. In addition to the name and value, each attribute has some value associated with it. Become attribute Properties

3. You can create an object by using the direct volume, the keyword new, and the Object.create () function

4. Object.create () is a static function that uses its method to pass in the desired prototype object

var child = Object.create (father)

5. You can create a new object without a prototype by object.create (NULL), but the object created in this way does not inherit any underlying method, such as ToString (). That is, it cannot work correctly with the "+" operator

6. If you want to create a normal empty object, you can use {} or New object () or Object.create (Object.prototype)

7. The properties in the prototype can be read directly from the object, but assigning a value to the property does not affect the value in the prototype

8. The delete operator can only delete its own property and cannot delete the inherited property

9. You can use the object's hasOwnProperty () method to detect whether a given name is an object's own property, and it will return false for inherited properties

propertyIsEnumerable () is an enhanced version of hasOwnProperty () that only returns true if its own property is detected and this property is enumerable

11. Each object has prototypes, classes, and extensibility

ES 5 provides built-in functions json.stringify () and Json.parse () to serialize and restore JavaScript objects

Five, array

1. JavaScript arrays are untyped, array elements can be of any type, and are not necessarily always bright, they can also be variables

2. JavaScript arrays are dynamic, and they grow or shrink as needed

3. The JavaScript array may be sparse, the index of an array element is not necessarily contiguous, there can be vacancies between them

4. Sparse arrays are typically slower to implement than dense arrays, and memory utilization is higher, and the time to find elements in such an array is as long as the regular object property lookup time

5. The length property of an array has three special behaviors:

    1. If an array element is assigned a value whose index exceeds or equals the current length, length automatically becomes n + 1
    2. When length is assigned less than the current array length, the array is truncated
    3. When length is assigned greater than the current array length, the array does not add new elements by default, but leaves a blank area at the end

6. The Array.push () method adds an element to the end of the array, using Array.pop () to delete an element at the end, and the array index is automatically maintained

7. The Array.unshift () method adds an element to the top of the array, using Array.shift () to delete the first element of the array, and the array index is automatically maintained

8. The Array.json () method, which converts all elements in an array into strings and joins them by default, uses the "," connection. You can also pass in a connector.

9. The Array.reverse () method reverses the order of the elements in the array, returning the inverse array. It takes the substitution, the original array will be changed

The Array.Sort () method sorts the elements in the array and returns the sorted array, with the array elements sorted in alphabetical order when the sort () is called without arguments

The. Array.concat () method creates and returns a new array whose elements include the original array that calls Concat (), and each parameter of concat ()

var a = [1, 2, 3]

A.concat (5, 6)//A = [1, 2, 3, 5, 6]

The Array.slice () method returns a fragment of an array that returns an array of indices from the first number to the one that does not contain a second number

The first two parameters of Array.splice () specify the array elements that need to be deleted, starting with the third argument, inserting the position indexed with parameter 1 in turn

var a = [1, 2, 3]

A.splice (1, 0, ' A ', ' B ', ' C ')//A = [1, 2, ' A ', ' B ', ' C ', 3]

In ES 5, you can use the Array.isarray () function to determine whether the object is an array. The code for the IsArray () function in ES 3 is as follows:

1 var function (o) {2     returntypeof o = = = ' object ' &&3     Object.prototype.toString.call (o) = = = ' [Object Array] '4 }

Five, function

1. When the method does not need to return a value, it is best to return itself (this) so that "chained calls" can be made

2. When a function is called, the default shape arguments is assigned a value of undefined if the passed argument is less than the formal parameter specified when the function is declared.

3. The function object can be linked by the scope chain, the variables inside the function body can be stored within the function scope, which is called "closure" in the computer science literature.

4. From a technical point of view, all JavaScript functions are closures, they are objects, they are all linked to the scope chain

5. If a function defines a nested function and returns it as a return value or stores it in a property somewhere, an external reference points to the nested function. He will not be treated as garbage collection, and the variable bound object it points to will not be garbage collected

6. The arguments.length in the function body represents the number of arguments passed into the function, and the length property of the function object represents the number of formal parameters

7. Call () and apply () are used to invoke the method, the first parameter is this, the difference is in the second argument, apply is passed in an array, and call is passed directly into the parameter list.

Calling function f () in the form of an object o can be written like this:

F.call (o, 1, 2)

F.apply (O, [1, 2])

The bind () method in 8.ES 5 binds a function to an object that can be easily simulated in ES 3:

  

1 functionbind (f, O) {2     if(f.bind) {3 4         returnf.bind (o)5 6}Else {7 8         return function() {9 Ten             returnf.apply (o, arguments) One         } A     } -}

JavaScript Knowledge Collation

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.