Skip to content

another curiosity about variable hoisting #343

Open

Description

@lewisje

The statement var something = something; works even as the first statement in its scope, because it is equivalent to

var something;
something = something;

and it, as imagined, sets something to undefined, even if something was already defined in an outer scope.

To make a local reference to an object in an outer scope with the same name, it needs to be passed in as a function parameter, because otherwise, the inner name will shadow the outer name because of hoisting.

Activity

  1. Cryptoxygen commented on Jan 22, 2019

    @Cryptoxygen

    Awesome post! Hoisting just make sense for for me now. :-)
    Thanks for spreading the knowledge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions