question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No rule for “Hoisting”

See original GitHub issue

The section “Hoisting” does a good job of explaining the ins and outs of hoisting, but states no rule about that.

For example I consider this a bad practice, because it leads to confusion and possible bugs:

function example() {
  superPower(); // => Flying

  function superPower() {
    console.log('Flying');
  }
}

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

12reactions
gregersryggcommented, Jun 27, 2015

I’m used to reading code top-to-bottom – and function hoisting is the only thing in JavaScript which breaks that rhythm.

I’d say it’s the rather opposite. With this rule you have to read the code backwards:

function c() {}
function b() { c(); }
function a() { b(); }
a();

Instead of:

a();
function a() { b(); }
function b() { c(); }
function c() {}

As far as I know, there are no side-effects of hoisting named function definitions, and it gives you the ability to have functions ordered in a more natural order. So my vote (if I have one 🐒) goes for relaxing this rule with “nofunc”.

The section for Functions is also kind of meaningless when it’s not allowed:

Why? Function declarations are named, so they’re easier to identify in call stacks. Also, the whole body of a function declaration is hoisted, whereas only the reference of a function expression is hoisted.

0reactions
jesucarrcommented, May 25, 2016

@ljharb you are right, in the actual implementation it will go inside a function so when called will have the right value. Overlooked that when doing the code simplification.

The design is based on the graphql interface type, like here, so I can’t redesign it.

But thanks for the clarification.

Read more comments on GitHub >

github_iconTop Results From Across the Web

1926.1431 - Hoisting personnel.
Personnel hoisting must not be conducted until the competent person determines that the platform and rigging have successfully passed the proof test. 1926.1431( ......
Read more >
Hoisting - MDN Web Docs Glossary: Definitions of ... - Mozilla
JavaScript Hoisting refers to the process whereby the interpreter appears to move the declaration of functions, variables or classes to the ...
Read more >
30 U.S. Code § 874 - Hoisting and mantrips - Law.Cornell.Edu
Where persons are transported into, or out of, a coal mine by hoists, a qualified hoisting engineer shall be on duty while any...
Read more >
4999. Handling Loads.
(h) Loads shall not be released or detached from a crane or other hoisting apparatus until the qualified person (rigger) detaching the load...
Read more >
Hoisting & Rigging Fundamentals
The safety policy “lf It's Not Safe, Don't Do ... the requirements of the DOE Hoisting and. Rigging program. It requires persons who...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found