GoConqr has a new look! Let us know what you think.

Mind map

Function

Nguyet Huynh JavaScript Beginner English

Map content

Function

  1. Definition

    • functionName(parameters){ code to execute }
    • var x = function(parameters) { code to execute }
    • EX: addNumber(a, b){ return a + b) }; x=addNumber(1,2)
  2. Parameter

    • Parameter vs argument
      • Paramter: names listed in function definition
      • Arument: real value passed to function
    • Parameter rules
      • not specify type
      • not perform type check on passed argument
      • not check number of argument received
    • Argument object
      • use when: too many arguments (more than declared)
      • arguments.length; arguments[i]
    • Cach truyen gtri
      • by value = arguments
      • by reference = object
  3. Closures

    • Global variables
      • lifetime: as long as application lives
      • all variable declare without var --> global variable (even if inside function)
    • Local variables = closure
  4. Invocation (goi ham)

    • goi giong o EX phan definition
    • Method of object: objectName.functionName();
    • function constructor
      • function myFunction(ar1, arg2){ this.firstName = arg1; this.lastName = arg2;}
      • var x = myFunction("John", "Joe"); x.firstName;
    • use function method
      • call()
        • var number; function myFunction(a,b){ return a*b;} number = myFunction.call(number, 10, 2)
      • apply()
        • var number, myArray; function myFunction(a,b){ return a*b;} myArray = [10,2]; number = myFunction.apply(number,myArray)
  5. Recursion = De quy

    • Syntax
      • Loop: var factor = function(number) { var result = 1; var count; for (count = number; count > 1; count--) { result *= count; } return result; }; console.log(factor(6)); // 720
      • Recursion: var countdown = function(value) { if (value > 0) { console.log(value); return countdown(value - 1); } else { return value; } }; countdown(10);
    • feature
      • call itself
      • 10 times slower than loop
      • s.times solve problem easier than loop
    • use for
      • iterative branching
      • such as: fractal math, sorting, or traversing the nodes of complex or non-linear data structures

Information

Description
Beginner JavaScript Mind Map on Function, created by Nguyet Huynh on 12/12/2015.
Created by
Nguyet Huynh
Views
0
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?