javascript中函数的写法
程序员文章站
2022-03-21 19:41:37
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <title>document</title> </head> <body> <script> //js函数的书写 function myfunction() { console.log("你好"); } //左边是funcion关键字 后面是函数名,里面写表达式 //带参数的两种写法 //1.在函数里面写实参 function myfunction(num,time,action) { var num=7,time="点",action="起床"; console.log(num + time + action); } //2.在调用函数的时候写实参 function myfunction(num,time,action) { console.log(num + time + action); } myfunction("7", "点","起床"); //带返回值写法 function myfunction(a,b){ var a=5,b=6; return a+b; } //外面接受返回值 function num(a,b) { return c=a+b; } var z=num(7,8); //通过=把return的值获取到 console.log(z); </script> </body> </html>