console
var globalVarlable1=0;
document.write(globalVarlable1+'</br>');
function test(){
var localVarlable1=2;
document.write(localVarlable1+'</br>');
}
var globalVarlable2=1;
document.write(globalVarlable2+'</br>');
function test1(){
var localVarlable2=3;
document.write(localVarlable2+'</br>');
}
function test2(){
document.write(localVarlable3+'</br>');
var localVarlable3=5;
}
test();
test1();
test2();
document.write(globalVarlable3);
var globalVarlable3=4;
document.write("<br>----------------------</br>");
function a1(){
document.write('Welcome to my world'+'</br>');
}
a1();
function add(left,right){
return left+right;
}
document.write(add(1,2)+3+'</br>');
function WelcomeMes(){
alert('Welcome');
}
document.write("<br>----------------------</br>");
function isLeapYear(year){
if(parseInt(year/4)==parseFloat(year/4)&&parseInt(year/100)!=parseFloat(year/100)){
return year+'是普通年';
}
else if(parseInt(year/400)==parseFloat(year/400)){
return year+'是世纪年';
}
else{
return year+'是其他年份';
}
}
document.write(isLeapYear(2000)+'</br>');
document.write(isLeapYear(2020)+'</br>');
document.write(isLeapYear(2021)+'</br>');
document.write(isLeapYear(4000)+'</br>');
document.write("<br>----------------------</br>");
function compareMax(arr1){
var Max=0;
for(i=0;i<arr1.length;i++){
if(arr1[i]>Max){
Max=arr1[i];
}
}
return Max;
}
var arr1=[2,8,3,6];
document.write('Max is '+compareMax(arr1));
<!DOCTYPE html>
<html>
<head>
<title>javascript函数</title>
</head>
<body>
<a href="javascript:WelcomeMes()">欢迎</a>
<br>--------</br>
</body>
</html>