Authoritative Guide learning experience-Statements

Source: Internet
Author: User

Function

// Recursive Functions function factorial (n) {  if(n<=1) {      return 1;  }   Else {      return N*arguments.callee (n-1);  }  } Console.log (Factorial (4)); //  -

A function scope is that all variables declared within a function are always visible in the body of the function, meaning that the variable is even available before the declaration, which is called the Declaration in advance, that is, all variables declared in the function (but not involving assignments) are advanced to the top of the function

Global variables are always defined in a program. A local variable is always defined within the body of the function that declares it and inside the function it is nested in.

The difference between a function declaration statement and a function definition expression

Both create a new function object, but the function name in the function declaration statement is a variable name, the variable points to the function object, and the function in the function definition statement, like the variable declared by Var, is displayed ahead of the steps or the top of the function. Therefore, they are visible throughout the script and in functions. With Var, only the variable declaration is in advance-the initialization code of the variable is still in its original position. However, the function name and function body are all in advance using the function declaration statement; All functions and functions in the footstep are preceded by other code in the current context, that is, you can call it before declaring a function.

For (variable in object)

Statement

Variable is usually a variable name, or it can be an expression that can produce an lvalue, or a variable declared through a var statement, in short it must be one that applies to an assignment expression. The value to the left of the type. Javascipt meeting Eat the properties of the enumeration object to perform the loop, before each loop, JavaScript evaluates the value of the variable expression and assigns the property name (a string) to it.

As long as the value of variable in the for/in loop can be used as the lvalue of an assignment expression, it can be an arbitrary expression. The entire expression is evaluated each time the loop is evaluated, which means that the value that it calculates may be different each time it is cycled.

For/in loops can enumerate the indexes of an array as if they were enumerated object properties

var o={x:1,y:2,z:3}; var a=[]; var i=0;  for inch o); Console.log (a); // ["X", "Y", "Z"]  for inch a)  {    Console.log (j)  }//

When break and tag are used, the program jumps to the end of the block of statements identified by the tag, or terminates the execution of the closed statement block directly. A tagged break statement is used when you want to jump out of the nearest loop body or switch statement by breaking

Authoritative Guide learning experience-Statements

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.