SOURCE

console 命令行工具 X clear

                    
>
console
//变量定义
var global1 = 0;

//document.write(local1+'<br/>');
//document.write(global2+'<br/>');

function test1(){
    var local1=2;

    document.write(global1+'<br/>');
    document.write(local1+'<br/>');
}

document.write(global2+'<br/>');

test1();

var global2 = 1;

function test2(){
    var local2=3;

    //document.write(local1+'<br/>');

}
test2();

document.write(global1+'<br/>');

document.write('<br/>-----------------<br/>');

//函数调用


//表达式调用
function addSum(a, b) 
{
    var sum = a + b;
    return sum;
}
        
//调用函数
    var n = addSum(1, 2) + 100;
    document.write(n);


//超链接调用
function welcomeMes(){
    alert("Welcome");
}

document.write('<br/>-----------------<br/>');

//判断闰年
function isLeapYear(year) 
{
        //判断闰年的条件
        if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0)) 
        {
            
            return year + "年是闰年";
        }

         else
            {
                return year + "年不是闰年";
            }
}
//调用函数
document.write(isLeapYear(2001)+'<br/>');
document.write(isLeapYear(2000)+'<br/>');
document.write(isLeapYear(2022)+'<br/>');
document.write('<br/>-----------------<br/>');

//求最大值
function getMax(a,b,c,d,e) 
{
    var maxNum;
    maxNum = (a > b) ? a : b;
    maxNum = (maxNum > c) ? maxNum : c;
    maxNum = (maxNum > d) ? maxNum : d;
    maxNum = (maxNum > e) ? maxNum : e;
    return maxNum;
}
document.write("5个数中的最大值为:" + getMax(3, 9, 1, 12, 50));

document.write('<br/>-----------------<br/>');


<!DOCTYPE html> 
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script>
        //var a;
        //document.write(a);
    </script>
</head>
<body>
    <a href="javascript:welcomeMes()">welcome to website</a>
</body>
</html>