123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <script>
- // var arr = [1,2,3,4,5];
- // var isInclude = false;
- // for(var i =0;i<arr.length;i++){
- // if(arr[i] == 3){
- // isInclude = true;
- // break;
- // }
- // }
- // console.log(isInclude)
- // console.log(arr.includes(3))
- // function 函数声明关键字
- // foo 代表函数名称
- // ()用作接受参数
- // {} 方法体
- // function foo(){
- // }
- // 函数定义及调用
- // function foo(){
- // console.log("hello");
- // }
- // foo();
- // 函数定义及传参
- // function foo(str){
- // console.log(str);
- // }
- // // foo("hello world");
- // var str1 = "hello world";
- // foo(str1);
- // 多参数函数
- // function addFun(a,b){
- // console.log(a+b);
- // }
- // addFun(1,2);
- // 带返回值的函数
- // function foo(){
- // // console.log("123");
- // return "loveCoding";
- // }
- // var str = foo();
- // console.log(str);
- // return 会结束函数的执行 后边的语句将不会执行
- // function foo(){
- // return "返回值";
- // console.log("hello");
- // }
- // foo();
- // 匿名函数定义方式
- // var foo = function(){
- // console.log("hello");
- // }
- // foo();
- // function foo(){
- // console.log("hello")
- // function foo2(){
- // console.log("world");
- // }
- // foo2();
- // }
- // foo();
- // 作用域
- function foo(){
- // 局部变量
- var a = 10;
- }
- foo();
- console.log(a);
- function foo2(){
- var a = 10;
- }
- function foo3(){
- var a = 12;
- }
- var a = 13;
- var a = 14;
- // 定义函数时参数为形参
- function foo(a){
- console.log(a)
- }
- //调用时的参数为实参
- foo(1)
- </script>
- </body>
- </html>
|