function hoisting first❗️

function hoisting has "higher" priority over variable hoisting.

JSscopehoistingfunction hoisting ⟩ first

in the same scope, function hoisting has higher priority over variable hoisting.

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"❗

Last updated