---
description: function hoisting has "higher" priority over variable hoisting.
---

# function hoisting first❗️

[JS](../../..) ⟩ [scope](../..) ⟩ [hoisting](..) ⟩ [function hoisting]() ⟩ first

{% hint style="success" %}
in the same [..](../.. "mention"), [](<> "mention") has <mark style="color:yellow;">**higher priority**</mark> over [variable](../variable "mention").
{% endhint %}

{% tabs %}
{% tab title="💈範例" %}
* replit：[function hoisting first](https://replit.com/@pegasusroe/function-hoisting-has-higher-priority#index.js)

```javascript
const { log } = console;

// <---- greeting === a "function" (at first)

// ⭐️ var hoisting has "lower" priority
var greeting;                    // ignored❗ (function hoisting first)

// ⭐️ function hoisting has "higher" priority
function greeting() {
    console.log("Hello!");
}

log(typeof greeting);            // at first, it's a "function"

// ⭐️ redeclaration ignored, 
// ❗ but assignment applied.
var greeting = "Hello!";        // now greeting is a string❗

log(greeting, typeof greeting); // 'Hello!', "string"❗
```
{% endtab %}

{% tab title="📗 參考" %}
* [ ] [ydkjs-scope-and-closures-v.2](../../../../master/ref/book/you-dont-know-js-series-v.2/ydkjs-scope-and-closures-v.2 "mention") ⟩&#x20;
  * [ ] [Ch. 1](https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/scope-closures/ch1.md#chapter-1-whats-the-scope) ⟩ [Hoisting](https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/scope-closures/ch1.md#hoisting)
  * [ ] Ch. 5 ⟩&#x20;
    * [ ] [Hoisting: Declaration vs. Expression](https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/scope-closures/ch5.md#hoisting-declaration-vs-expression)
    * [ ] [Re-declarations?](https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/scope-closures/ch5.md#re-declaration)
{% endtab %}
{% endtabs %}
