# 1.2.3.6.函數陳述句與函數表示式

* 表達式 (expression)
  * 程式碼的單位, 最終會形成一個值
* 函數陳述句&#x20;
  * 不會回傳值, 但是會做特別的事如[hoisting](https://jenhsuan.gitbooks.io/javascript-node-js/content/chapter1/121zhi-xing-huan-jing-yu-ci-hui-huan-jing/1212zhi-xing-huan-jing-ff1a-chuang-zao-yu-ti-sheng.html), **在執行環境的創造階段就會將函數放進記憶體中**
* 將函數給另一個函數使用, 是**函數程式語言 (functional programming)**&#x7684;概念

```
//表達式
var a;
a = 3;
1 + 2;
a = {greeting: 'hi'}

//if陳述句 
if (a == 3){
}

//函數陳述句: 不會回傳值
greet();

function greet() {
    console.log('hi');
}

//函數表達式: 變數將會指向記憶體的位置, 因為函數在宣告就已經在記憶體中佔有位置了

//執行會失敗, 因為anonymousGreet在執行階段才會被賦值, 此時還是undefined
//函數表達式沒有被提升
anonymousGreet();

var anonymousGreet =  function() {
    console.log('hi');
}

//執行成功
anonymousGreet();

function log(a){
    console.log(a);
}

//印出3
log(3);

//印出Hello
log("Hello")

//印出Object {greeting: "hi"}
log({greeting: 'hi'})

//將函數放到函數的CODE property
//印出function() {
//    console.log('hi');
//}

log(function() {
    console.log('hi');
})

//使用傳入的函數
//印出'hi'
function log(a){
    a();
}

log(function() {
    console.log('hi');
})
```

![](/files/-M4M0MvZ44mou9d5cu6f)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jen-hsuan-hsieh.gitbook.io/javascript-node-js/chapter1/12javascript-quan-gong-lve-ff1a-ke-fu-js-de-qi-guai-bu-fen/123wu-jian-yu-han-shu/1236han-shu-chen-shu-ju-yu-han-shu-biao-shi-shi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
