js-- function Introduction

function:

Or functions are reusable blocks of code when it is called for execution of the event driven.

Functiuon method name (parameter) {} method thereof

function myFunction(a, b) {
    return a * b;
}

 

transfer:

Method name (arguments);

function myFunction(a, b) {
    return a * b;
}

After the first call can be defined as follows:

var z = x(4, 3);
var x = function (a, b) {return a * b};

 

Function calls with arguments

When you call the function, you can pass it a value, these values ​​are called parameters.

These parameters may be used in the function.

You can send any number of parameters, (,), separated by commas.

 

Return Return Values

We want the function to return the value of its local calling.

When using the return statement, the function stops execution and returns the specified value.

In order to calculate the next step;

function myFunction(a, b) {
    return a * b;
}

var x = myFunction(4, 3) * 2;
x=24;

 

In JavaScript variables declared inside a function (var) it is a local variable, so it can only be accessed inside the function, and will not affect the entire page.

 

Guess you like

Origin www.cnblogs.com/layuechuquwan/p/11183102.html