JavaScript笔记-函数
https://www.liaoxuefeng.com/wiki/1022910821149312基于廖雪峰老师的教程所做的笔记。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 <!DOCTYPE html > <html lang ="en" > <head > <meta charset ="UTF-8" > <title > 函数基本操作展示</title > </head > <body > <script > function abs (x ) { if(x>0){ return x; } else { return -x; } } console .log(abs(-1 )); var square=function (x ) { return x*x; }; console .log(square(2 )); function add (a,b ) { } console .log(add(1 ,2 )); function show ( ) { console .log("Show Time!" ) for (var val of arguments ){ console .log(val); } } show("We" ,"are" ,"arguments!" ) function sub (a,b ) { return a-b; } console .log(sub(1 )); function sum (a,b,...rest ) { var ans=0 ; ans=a+b; for (var val of rest){ ans+=val; } return ans; } console .log(sum(1 ,2 )); console .log(sum(1 ,2 ,3 ,4 )) function get ( ) { return { name:"Sang" }; } </script > </body > </html >