<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv ...
<!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>