<!DOCTYPE html>
<html lang=
"en">
<head>
<meta charset=
"UTF-8">
<meta name=
"viewport" content=
"width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
//方案1,比较冗长
function isou(num){
if(num%2==0){
return true
;
}else{
return false
;
}
}
var result=
isou(7
);
document.
write(result
);
document.
write("<hr>");
//方案2,简约版
function isou (num){
return num%2==0
;
}
var result=
isou(3
);
document.
write(result
);
document.
write("<hr>");
</script>
<script>
function area(r){
return 3.14*r*r
;
}
result=
area(10
);
document.
write(result
);
document.
write("<hr>");
//方案1
function sayHello(a){
document.
write("我是"+a.name+
",今天我"+a.age+
"岁了,我是"+a.gender+
"生,我的地址是"+a.adress
);
}
//
sayHello("晴天",18,
"女",
"陕西");
//document.
write("<hr>");
//方案2
//创建一个对象
var obj={
name:"孙悟空",
age:18,
gender:"男",
adress:"花果山"
};
sayHello(obj
);
function fun(a){
console.
log("a="+a
);
//
a(obj
);
}
//
fun(sayHello
);
fun(function(){alert("hello")});
document.
write("<hr>");
fun(area(10
));
</script>
</head>
<body>
</body>
</html>