# 变量提升和声明作用域

```javascript
b = c;

b();
console.log(a);    //1
console.log(b);    //2
console.log(c);    //3

function c() {
    a = 1, b = 2, c = 3;
};

// 将上述代码稍作修改:

b = function c() {
    a = 1, b = 2, c = 3;
};

b();
console.log(a);    //1
console.log(b);    //2
console.log(c);    //Uncaught ReferenceError: c is not defined

// 再次将上述代码稍作修改:

b = function c() {
    a = 1, b = 2, c = 3;
    console.log(a);    //1
    console.log(b);    //2
    console.log(c);    //fuction c(){...
};
b();

```

### 解析

函数声明 的优先级 **高于** 变量声明的优先级，但 **不会** 覆盖变量赋值。

> 对于 `var bar = function foo(){};` 语句，其实就是一个有效的命名函数表达式，但有一点需要记住：这个名字只在新定义的函数作用域内有效，因为规范规定了标示符不能在外围的作用域内有效：
>
> ```javascript
> var f = function foo(){
>     return typeof foo; // foo是在内部作用域内有效
> };
> // foo在外部用于是不可见的
> typeof foo; // "undefined"
> f(); // "function"
> ```

记住一点： 命名函数表达式的标示符（即函数名称）在外部作用域是无效的


---

# 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://mm.ricky.moe/interview/inverview-record/javascript-questions/bian-liang-ti-sheng-he-sheng-ming-zuo-yong-yu.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.
