<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>入门</title> </head> <body> <script> //函数 = 方法 /* 方法 参数 返回值 */ //格式1 function method1(a){ console.log("method1") console.log("参数"+a); } //调用 method1(20); function method2(){ return "hello js"; } //调用 let b = method2(); console.log("返回值:"+b) //格式2 let m1 = function (){ console.log("m1") } //调用 m1() m1() /* 打印机: 将指定的字符串传入函数内,在浏览器形成打印机的效果. */ let s = "将指定的字符串传入函数内,在浏览器形成打印机的效果"; function print(s){ let s1 = ""; let body = document.getElementsByName("body")[0]; //遍历 for (let i = 0; i < s.length; i++) { s1 += s.charAt(i) console.log(s1) } } print(s) /* 闰年判断: 判断是否时闰年,输入年份判断是否时闰年返回boolean值. */ function isYear(year){ return (year % 4== 0 && year % 100 == 0) || year % 400 == 0 ; } //调用 console.log("是否是闰年:"+isYear(2000)) </script> </body> </html>