Skip to content

Unclear code example in variables section #136

@Daniel-Hug

Description

@Daniel-Hug

At the bottom of the variables section, this code example is given:

// bad
function() {
  var name = getName();

  if (!arguments.length) {
    return false;
  }

  return true;
}

// good
function() {
  if (!arguments.length) {
    return false;
  }

  var name = getName();

  return true;
}

At the top of that code block it says:

Assign variables at the top of their scope. This helps avoid issues with variable declaration and assignment hoisting related issues.

It's not clear what point the code example is trying to make, as it doesn't reflect the statement made in that comment. Plus, the name variable is defined but never used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions