JavaScript Basics Review/re-learn

Source: Internet
Author: User
Tags closure

It is better to study again than to review. Here is a record of what you want to record in your learning process so that you can review it later.

ECMAScript raw Data type : String, Number, Boolean, Undefined, Null

Calling the TypeOf operator on a variable or value returns one of the following values: undefined-If the variable is a string of type undefined-if the variable is a number of type string-if the variable is a Boolean of type number- If the variable is an object of type Boolean-if the variable is a reference type or a null type function-if the variable is a function ECMAScript operator Unary OperatorsDelete can only delete developer-defined properties and methods, and cannot delete ECMAScript's original method, such as ToString ()
var o={name: "Minnie", Age:8};alert (o.name); // output Minnie; Delete O.namealert (o.name); // output undefined;
The void operator returns undefined for any value. This operator is often used to avoid output values that should not be output. For example
<href= "Javascript:window.open (' About:blank ')">click me </ a >
When you click on the "click Me" on the page, you can see "object" on the screen and use
<href= "javascript:void (window.open (' About:blank ')")>click me  </a>
void causes window.open () to return a undefined,undefined that is not a valid value and is not displayed in the browser window.Note: The "object" condition is not present in the high-version browser Pre increment/decrement operator ++/--operatorThe addition and subtraction is performed before the expression is evaluated, so it has been added to the execution of the expression, so the value of the expression is consistent with the value of the parameter. The special language of javascript:1. The global variable 2 can be read directly inside the function. Declaring a variable inside a function must be VAR, otherwise it declares a global variable (global variable declaration can be used without Var) maximum benefits of closures:1. Access the variables inside the function outside of the function 2. Keep the values of these variables in memory at all times Disadvantages of closures:1. Closures will make the variables in the function are stored in memory, memory consumption is very large, so can not abuse closures, otherwise it will cause the performance of the Web page, in IE may cause memory leaks. The workaround is to remove all unused local variables before exiting the function. 2. Closures change the value of a function's internal variables outside the parent function. Therefore, if the parent function is used as an object, the closure as its common method, the internal variable as its private property, it is important to be careful not to arbitrarily change the value of the internal variables of the parent function. closure Trap One:
function createfunctions () {  varnew  Array ();    for (var i=0; i <; i++) {    function() {      return  i;    } ;  }   return result;} var funcs = createfunctions ();  for (var i=0; i < funcs.length; i++) {  console.log (Funcs[i] ());}
At first glance, thought output 0-9, actually output 10 10; the trap here isfunction Band () is the execution functionSummary: A closure is a variable in which a function refers to another function, because the variable is referenced so it is not recycled, and unnecessary references (closures) are the acts of increasing memory consumption. JavaScript prototypes (prototype chains and scope chains)Everything (reference type) is an object, and the object is a collection of properties. --------------------------------------------------------------------------------------------------------------- --- the difference between = = and = = == = Equals (value) converts a reference type to a base type for comparison using = = when the reference type is first converted to the base type.when an object is converted to a base type, the default is to use valueof to go first, then use ToString () to go, and date with ToString () to。 The following code tests:
var x = ""; var function () {x= "toString"; return function () {x= "valueOf"; return 0}};console.log (obj==0,x); // true, "ValueOf" var x = ""; var function () {x= "toString"; return 0}};console.log (obj==0,x); // true, "toString"
Using = = can also have side effects, and may even produce anomalies.
var x = ""; var function () {x= "toString"; return {}}};console.log (obj==0,x); // uncaught typeerror:cannot Convert object to primitive value
= = = Congruent (value and type)---------------------------------------------------------------------------------------------------- __proto__Each object has a __proto__ property, The prototype that points to the function that created the object.---------------------------------------------------------------------------------------------------- -- instanceof operatorJudgment rule: a instanceof B   (Personal understanding is: To determine whether A is a prototype of B. A (the object has a hidden property __proto__) B (the function has a default property of prototype)) a--object  b--function instanceof The judging rule is: go along the __proto__ of a. At the same time, follow the line of prototype B to find, if the two lines can find the same reference, that is the same object, then return true; If the focus is not coincident, return false. For example:
 Console.log (Object instanceof  Function); // true  // object.__proto__ = = = Function.prototype  console.log (Function instanceof  Object"); // true  // function.__proto = = = Function.prototype = = = function.prototype.__proto__ Object.prototype;  Console.log (function instanceof  Function); // true  // function.__proto__ = = = Function.protorype  
Summary: instanceof represents an inheritance relationship, or the structure function of a prototype chain is an object that is generated by a function. --------------------------------------------------------------------------------------------------------Object.prototype . hasOwnProperty all objects have object.prototype methods, all functions have call,apply methods, and all have length,arguments,caller properties. -------------------------------------------------------------------------------------------------------In operatorProp in object specifies the attribute (only the property name, the array can only be an index value) that exists in the specified object Delete an attribute using the delete operator, the In operator returns false for the deleted property:
var str = {"name": "Minnie", "Age": 8, "class": "Xiaoxue"}; Delete Str.class;  in str; // false;
assigning a property to a value of undefined, the in operator still returns true.
var str = {"name": "Minnie", "Age": 8, "class": "Xiaoxue"= undefined;  in str; // true
If the property is inherited from the prototype chain, the in operator also returns true
inch {}; // true
variables, function declarations, function expressionsJavaScript is prepared before executing a code snippet, and then the code executes. This "code snippet" is divided into three scenarios-Global, function, eval preparation: 1. Declaration of a variable 2. The variable declaration on a function expression is assigned a value of undefined 3.this by default. function declaration--assignment these steps make up the execution context or the execution context

JavaScript Basics Review/re-learn

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.