123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <script>
- function num(x, y) {
- console.log(x + y)
- }
- num(10, 5)
- /* JavaScript 函数通过 function 关键词进行定义,其后是函数名和括号()。
- 函数名可包含字母、数字、下划线和美元符号(规则与变量名相同)。
- 圆括号可包括由逗号分隔的参数 */
- // function area(){
- // var a = window.prompt('请输入三角形的底边长度',"")
- // var b = window.prompt('请输入三角形的高度',"")
- // var c = a*b/2
- // alert('三角形的面试是'+ c)
- // }
- // area()
- // var d = 111 //全局变量
- // function num1(){
- // var b = 123 //局部变量
- // console.log(b)
- // }
- // num1()
- // console.log(b)
- //局部变量只能在局部访问 在全局访问不到
- //全局变量 能在 所有地方 访问
-
- var z = 111;
- fun()
- console.log(z)
- function fun(){
- console.log(z)
- z = 110
- console.log(z)
- }
-
-
- </script>
- </body>
- </html>
|