SOURCE

console 命令行工具 X clear

                    
>
console
var globalVariable1 = 0;

function test1() {
    document.write(localVariable1+ "<br/>");
    var localVariable1 = 2;
    //打印globalVariable1
    document.write(globalVariable1 + "<br/>");

    //打印localVariable1
    document.write(localVariable1+ "<br/>");
}

//打印localVariable1
//document.write(localVariable1);

//打印globalVariable2
document.write(globalVariable2 + "<br/>");


test1();

var globalVariable2 = 1;

function test2() {
    var localVariable2 = 3;

    //打印localVariable1
    //document.write(localVariable1 + "<br/>");

}
test2();

//打印localVariable2
//document.write(localVariable2 + "<br/>");
//打印globalVariable1
document.write(globalVariable1 + "<br/>");

function welcomeMes(){
    alert("Welcome");
}

function add(left, right) {
    return left + right;
}

document.write((add(1, 2) + 3) + "<br/>")

function isLeapYear(year) {
    var result = false;
    //判断是否是闰年

    if ((year % 4 == 0) && (year % 100 != 0)) {
        result = true;
    }

    if (year % 400 == 0) {
        result = true;
    }

    if (result) {
        document.write( year + " is a leap year. <br/>");
    }
    else {
        document.write( year + " is not a leap year. <br/>");
    }
    

}

//打印2020,2000,2001是否是闰年
isLeapYear(2020);
isLeapYear(2000);
isLeapYear(2001);












function getMax(a,b,c,d) {
            var maxNum;
            maxNum = (a > b) ? a : b;
            maxNum = (maxNum > c) ? maxNum : c;
            maxNum = (maxNum > d) ? maxNum : d;
            return maxNum;
        }
        document.write("4个数中的最大值为:" + getMax(1, 2, 4, 3));
<!DOCTYPE html> 
<html>
<head>
    <meta charset="utf-8" />
    <title>Javascript函数</title>
</head>
<body>
    <div>
        <a href="javascript:welcomeMes()">Welcome</a>
    </div>
    
</body>
</html>