123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <!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>
- // function foo(){
- // console.log("hello world");
- // }
- // foo();
- // function foo(str){//str 为函数参数 (形参)
- // console.log(str);
- // }
- // foo("hello world");//hello world 为函数实参 (实参)
- // 如果多个参数,用逗号隔开
- // function foo(a,b){
- // console.log(a+b);
- // }
- // foo(1,2)
- // 函数可以返回值 实用return 但如果执行renturn后,后面的代码将不再执行
- // function foo(a){
- // a = a * 1;
- // return a;
- // console.log("end");
- // }
- // var num = foo("123");
- // console.log(num + 1);
- // 匿名函数
- // var foo = function(){
- // console.log("hello world");
- // }
- // foo();
- // 函数内部可以访问全局变量
- var a = 20;
- function foo(){
- // 函数内部可以定义变量 但是不能被外部访问 局部变量
- // var a = 10;
- console.log(a);
- }
- foo();
- </script>
- </body>
- </html>
|