<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>函数</title>
</head>
<body>
<script type="text/javascript">
function fn01(a,b){
console.log(a+b);
}
console.log(fn01);
var fn02=function(a,b){
console.log(a+b);
}
var fn03 = new Function('a','b','return (a+b);');
function fn04(a,b){
return (a+b);
}
console.log("==================");
function test01(x,y){
console.log(x+y);
}
test01();
test01(1);
test01(1,2);
function test02(x,x){
console.log(x);
}
test02(1,2);
function test03(x){
x= x||"x";
console.log(x);
}
test03(10);
test03();
function test04(x){
(x !=null && x !=undefined)?x=x:x="x";
console.log(x);
}
test04();
test04("hello");
var num =10;
function test05(num){
num=20;
}
test05(num);
console.log(num);
var obj={name:"zhangsan"};
console.log(obj);
function test06(o){
o.name = "lisi";
}
test06(obj);
console.log(obj);
console.log("==================");
function f1(){
console.log("常用调用模式...");
}
f1();
var f2= function(a){
console.log("函数调用模式...");
return a;
}
var num1= f2(1);
console.log(num1);
var obj={
name:"zhangsan",
age:18,
sex:true,
cats:["大毛","二毛"],
dog:{
name:"张二狗",
age:1
},
sayhello:function(){
console.log("你好呀~");
}
}
console.log(obj);
console.log(obj.dog);
console.log(obj.sayhello);
obj.sayhello();
console.log("==================");
function a1(){
console.log("没有返回值...");
return;
console.log("---------");
}
console.log(a1());
function a2(){
console.log("有返回值...");
return "test";
}
console.log(a2());
console.log("==================");
var pp = "hello";
function qq(){
var box1= 10;
box2 = 20;
}
qq();
console.log(pp);
console.log(box2);
</script>
</body>
</html>