How does Hoisting work in Javascript?

Asked

Viewed 32 times

0

The site w3schools informs that variable and function statements are moved to the top of the code.

Already the site of MDN says that Hoisting does not actually move statements to the top, but rather that they are loaded first into memory, maintaining the order you have programmed.

The two definitions allow the following encoding:

dizerNome("Rafael");

function dizerNome(nome) {
    console.log("O nome do estudante é " + nome);
}

However, this example of mine above after the compilation, what will really happen to it? The function will be moved up or loaded first into memory?

  • 1

    The two sites are saying the same thing in different ways. The point of MDN is that "moving to the top" is a way of explaining how the thing works conceptually, but that in the implementation only matters when each thing is loaded into memory. That is, there is no "little robot" moving the lines of your place code, it’s just a way to explain the effects of Hoisting.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.