Java Script The 11th lesson in Java script in the functions-through function key

Source: Internet
Author: User

<! DOCTYPE html>

<meta charset= "Utf-8" >

<title></title>

<body>

<script type-"Text/javascript" >

The first chapter, the Custom function.

test ();

function Test () {

Alert (' This is a test ');

}

Test ();

Function names are strictly case-sensitive

function TEST () {

Alert ("Hello King");

}

TEST ();

Duplicate function name will result in overwrite

Test ();

function Test () {

Alert (' Hello Maizi ');

}

Test ();

function Test1 () {

Alert (' This is test1 function ');

}

Alert (test1 ());

function Test2 () {

return null;

return undefined;

Return

return true;

Return ' This is king ';

return 1.2;

Alert (' This is a test ');

return 1;

}

alert (test2 ());

The function returns the value by return and returns the undefined if no return is returned by default

Function names do not contain special characters

Function names are best followed by hump notation or underline notation

Functions can have parameters or can have no parameters, can have one argument or can have multiple parameters

function expressions can be stored in variables, and variables can also be used as a function

Anonymous functions can be passed as arguments to other functions, and the receiving function can perform certain functions by passing in functions

You can perform some one-time tasks through anonymous functions

Function Calc (num1,num2) {

return num1+num2;

}


Alert (calc);

The third chapter calls the function.

Called through the window. function name ()

alert (Window.calc (2,3))

Chapter three parameters.

JS ignores extraneous parameters when passing parameters that exceed the defined parameters when invoking a function

Alert (Calc (1,2,3,4,5,6,7,8,9))

Parameters (Arameter)

JS cannot directly write default values, you can use the arguments object to achieve the default value effect

function Calc1 (num1,num2) {

num1=num1| | 1;

num2=num2| | 2;

return num1+num2;

}

Alert (Calc1 (3,5));

</script>

</body>


Java Script The 11th lesson in Java script in the functions-through function key

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.