Note the front end of 6-js2

1.break and continue usage

break this cycle ends, if you want to end the outer loop, you can specify the end of the cycle through this label.

It can be used to continue to skip cycles when, if you want to skip the outer cycle, can also be specified to skip circulated through the label.

Hello:
for (var I = 0; I <. 5; I ++) {
  the console.log ( "outer loop:" + I);
  for (var J = 0; J <. 5; J ++) {
    the console.log ( "- ----> inner loop: "+ J)
    IF (J == 2) {
      BREAK Hello;
      }
    }
  }

2. Timer

console.time () can be used to turn on a timer, this timer may be used to perform the recording time of the program

 This method takes a string as a parameter, as this string will timer identification
console.time ( "test");

 console.timeEnd () can be used to stop a timer, the method requires a string argument is the string to stop the timer identification
console.timeEnd ( "test");

3. Object

* JS in a total of six types of data
* basic data types
* Number The Boolean String Null Undefined
* reference data types
* Object (Object)

1. Create an object method 1

var obj = new Object();

obj.name = "Monkey";
obj.age = 18 is;

/ *
* Delete object attributes
. * Syntax: delete object property name
* /
// delete the name attribute of obj
delete obj.name;

2. Create Object Method 2

var obj = {};

* The second way to add properties
* Object [ "attribute name"] = value attribute
* [] used in this way than we do. More flexible, and [] can pass variables

obj [ "123abc"] = "hello" is equivalent to obj.123abc = "hello";

obj2 = {var
  name: "Monkey",
  Age: 18 is,
  address: "Huaguoshan",
  "123": "Hello",
  Test: {
    name: "Pig",
    Age: 28,
    address: "Gao Village"
  }
};

4. Garbage Collection

* Garbage collection (GC)
* - When an object does not have any variables when its reference
* At this point we will not be able to get to the object and can not do any operation on the object
* However, this target will still occupy memory space, this garbage can waste a lot of memory after too many
* cause the program to run slower. We must be recovered to such an object, it does not take up memory space.
*
* - automatic garbage collection mechanism in the JS, the Object Browser will not automatically be removed from the reference memory.
* Recovery work is done automatically by the browser, and we only need to set up some unused objects can be null

5. enumeration property

// Create an object
var obj = {
  name: "Pig",
  Age: 28,
  address: "Gao Village"
};

// to enumerate the attributes from obj
/ *
* Use for ... in statement to an object attribute enumerated
* Syntax:
* for (variable in object) {
*
*}
*
* There are several objects attribute, the loop will be performed several times,
* each execution will assign the attribute name in an object to a variable
* /

for(var n in obj){
  console.log(n + " : " +obj[n]);
}

 

6 function

// Create a function, method. 1
function Fun () {

the console.log ( "a statement");
}

// Create a function, method 2

- Syntax:
 var variable = function ([parameter 1, parameter 2, ... parameter n]) {
  statements ...
 };

fun2 function = var () {
Alert ( "I is another function");
};

 

Call the function: fun2 ();

Guess you like

Origin www.cnblogs.com/liuyi13535496566/p/11968506.html