Definition of number 10.9th function

Source: Internet
Author: User

    1. Functional keyword function

Review

Var is the keyword of JS, used to declare variables, declared in memory module completion, definition (=) is done in the execution module.

var can be done in advance of the memory module (before the JS code executes) so there are variables to promote this function.

Because a does not have Var, there is no variable promotion, and the browser treats him as a property of window.

function is also the keyword of JS, for declaring and defining functions, declarations and definitions are completed in the memory module.

function is also the memory module is completed ahead of time, so there are functions to promote this function.

Variable promotion and function promotion are called pre-interpretations. are browser-only.

2. Function definition: function: A block of code with certain functions.

functions are defined by functions, followed by function names.

Structure syntax

function fn () {}

We can find that the memory module only exists var variable name. Instead, the entire block of code is stored, because declarations and definitions are done at the same time.

The attention of the function structure

function definitions define function fn () {} by function

Four ways to define a function

  1. Declarative definition function fn () {}
  2. Expression-defined var an=function () {} anonymous function
      1. Self-invoking

    Both definitions and calls are completed at the same time.

    4. Through the form of the object Var as=new Function () {}

    function call Function name () FN ()

    The biggest advantage of the function is that it forms a separate module that can be used on demand and can be reused.

    Use on demand reduces code redundancy (Rong) redundancy by improving performance reuse.

    Procedure for function calls

    When the function executes, it forms a private scope of its own. The largest scope is window (global scope)

    Then execute the code block inside the function.

    Scope chain: When a variable inside a function is used, the variable is first looked up under its own private scope, there is a direct use, no one will be found to his upper level, the parent uses the parent, and the parent does not continue to look up until the window, the window has no use is Not defined. This lookup mechanism we call the scope chain.

    The function belongs to who, and where she is called has no relationship, but in which definition is concerned.

    function recursion: Inside the function internally calls itself

    Break and Continue operations

    Break terminates the current program

    Continue jumps out of the current program and executes the next

    Console.log (a)
    Console.log (b)
    var a=12;
    b=12;
    function fn () {
    Console.log (12)
    //}
    FN ()
    function fn () {
    Console.log (123)
    //}
    As ()
    var as=function () {
    Console.log (12)
    //}
    var a=12;
    function fn () {
    Console.log (a)
    var a=144;
    Console.log (a)
    //}
    //
    function fn () {
    Console.log (123);
    function ff () {
    Console.log (52)
    }FF ()
    }FN ()
    FN ()
    var sum=0;
    var I=1;
    function fn () {
    Sum=sum+i;
    i++;
    Console.log (SUM)
    FN ()
    //}
    FN ()
    (function () {
    Console.log (412)
    //})()
    !function () {
    Console.log (12)
    //}()
    var a = 123;
    function Fun () {
    alert (a);
    A = 456;
    }
    Fun ();
    alert (a);

Definition of number 10.9th function

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.