Skip to content

another curiosity about variable hoisting #343

@lewisje

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.

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