<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title></title>

</head>

<body>

<script type-"text/javascript">

//第一章节,自定义函数。

// test();

function test(){

alert('this is a test');

}

// test();

//函数名称严格区分大小写

function TEST(){

alert("hello king");

}

// TEST();

//函数名称重复会产生覆盖

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());

//函数通过return加返回值,如果没有return 默认返回undefined

//函数名称不要包含特殊字符

//函数名称最好遵循驼峰标记法或者下划线标记法

//函数可以有参数也可以没有参数,可以有一个参数也可以有多个参数

//函数表达式可以存储在变量中,变量也可以作为一个函数使用

//可以将匿名函数作为参数传递给其他函数,接收函数就可以通过传递进来的函数完成某些功能

//可以通过匿名函数来执行某些一次性的任务

function calc(num1,num2){

return num1+num2;

}


//alert(calc(1,2));

//第三章调用函数。

//通过window.函数名称()进行调用

// alert(window.calc(2,3))

//第三章参数。

//JS在调用函数时如果传递参数超过了定义时参数,JS会忽略掉多余的参数

//alert(calc(1,2,3,4,5,6,7,8,9))

//参数(arameter)

//js中不能直接写默认值,可以通过arguments对象来实现默认值效果

function calc1(num1,num2){

num1=num1||1;

num2=num2||2;

return num1+num2;

}

alert(calc1(3,5));

</script>

</body>

</html>