JS Basics, you need to master the essentials!

Source: Internet
Author: User

"Loop control Statement"
1, break: Terminate this layer loop, continue to execute the statement behind the loop;
When a loop has multiple layers, break only skips a layer of loops;
2, continue: Skip this cycle, continue to perform the next cycle;
For for,continue execution, continue to execute the Loop variable UPDATE statement n++
For while,do-while,continue execution, continue to execute the cyclic condition, judging; So when using these two loops, you must be careful

Continue must be after n++, otherwise it will cause a cycle of death.

"Nested loop characteristics"
Outer loop control number of rows, inner loop controls the number of elements per row

[To do the graphic problem thinking]
1, determine the graph altogether several lines, namely is the outer circle the frequency;
2, to determine that each line has several elements, representing a few inner layers of the loop;
3, determine the number of elements, that is, the number of cycles per inner layer;
Tips: Usually, find out the number of each element, the relationship with the line number, that is, the maximum value of the current inner loop (starting from 1 cycles)


"Declaration and invocation of functions "
1. Function declaration format:
function name (parameter 1, parameter 2, ...). ) {
//function Body
return result
}
the format of the >>> function call:
The function name (the value of parameter 1, the value of parameter 2, ...). )
2, the function declaration of several emphasis:
Declaration of the ① function name: must conform to the small hump rule (first letter lowercase, and then each word capitalized in the first letter);
② parameter list: can have, no parameter, respectively is the parameter function and the parameterless function;
③ A parameter list when declaring a function, called the "formal parameter function" (the name of the variable);
A list of arguments called the function, called the argument function (the value of the variable);
function, the actual valid arguments depend on the assignment of the argument, the parameter that is not assigned, and will be the value of the
Undefined;
④ function If a return value is needed, return the result using return,
when calling a function, accept the return result by using the var variable name = function name ();
If the function does not return a value, the accepted result is undefined.
Scope of variables in the ⑤ function:
In a function, a variable declared with VAR, which defaults to a function local variable, is only available inside the function;
variables declared without VAR, default to global variables (global variables in functions, must be used after function calls)
the formal parameter list of the function, which is the function local variable, is used only inside the function;
⑥ function declaration and function call, there is no successive points. That is, the invocation statement can be written before the declaration statement.

"Declaration and invocation of anonymous functions"
1, declare an anonymous function, directly assigned to an event;
window.onload=function () {}
2. Declare an anonymous function using a function expression:
declaring function expressions: var func = function () {}
Call Function Expression: func ();
>>> using an anonymous function expression, the calling statement must be followed by an error after declaring the statement (comparing the general function declaration to the call)
3. Declare and invoke the anonymous function directly using the self-executing function:
!function (Parameter 1) {} (value of parameter 1);//start with any operator, use it normally!
(function () {} ())//use () enclose the anonymous function and the following parentheses
(function () {}) ()//use () to wrap only anonymous function expressions
three types of writing features:
① Structure Clear, beginning add! , End Plus (), not easy to mess, recommended use
② can indicate that the anonymous function and the following () are a whole, it is recommended to use
③ cannot indicate that the anonymous function and the following () are a whole, and it is not recommended to use


"Properties inside a function"
[Arguments Object]
1, function: Used to save the calling function, the value of the argument list assigned.
>>> when we call a function and assign a value using an argument, the argument is actually saved to the arguments array,
Parameters can be called using arguments[n], even without formal parameters;

2. The number of arguments arrays depends on the argument list, regardless of the parameter;
However, when the nth position of the formal parameters, arguments, arguments are present,
The arguments is synchronous in shape. (That is, you modify one of the values in the function and the other synchronizes
Change

3. Arguments.callee is an important attribute of arguments, which is used to return the reference of arguments function;
Arguments.callee () can invoke its own function execution;

Calling the function itself in the function itself is called recursion, so Arguments.callee () is a common method of recursive invocation;

[This]
The scope where the function call statement is located, that is, who called the function, this is who;


"JS"
console.log (num);
var num = ten;
function func () {}
js in the code run, will be checked, loaded, that is, declaring variables, functions and so on;


Therefore, the declaration of the function belongs to the check loading stage, The call to the function belongs to the execution phase, and the
so, the function call statement is written before the function declaration statement, and there is no relationship.

So the above code execution process:
------check the load stage--------
var num;//DECLARE variable
function FuncN ()//Declaration function

------Execution Phase-----------
Console.log (num);
num=10;
FuncN (); Code in {} that executes the function

JS Basics, you need to master the essentials!

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.