1)代碼重用編程
2)模塊化編程模塊化
1)系統函數函數
alert();spa
confirm();code
toString();blog
2)自定義函數ip
使用函數前要先定義才能調用io
函數定義有三個部分:函數名,參數列表,函數體function
定義函數的格式:class
function 函數名([參數1,參數2…]){
函數執行部分;
return 表達式;
}
函數形參:在函數定義時所指定的參數
函數實參:在函數調用時所傳遞的參數
函數的名稱也是一種特殊的量,能夠把它賦值給變量,代碼以下
<script> function display(){ alert(「hello world」); } var i = display(); i(); </script>
改寫上面代碼,以下所示:
<script> var i = function(){ alert(‘hello world’); } i(); </script>
咱們把這種沒有名字的函數就稱之爲匿名函數。