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-use-before-define.js: ignore hoisted named function expressions

See original GitHub issue

When you declare a function via a named function expression, e.g. function myFunc() {};, JavaScript hoists that function so it is available before evaluation within the context in which is was declared. Currently the no-use-before-define.js rules throws a warning for this common use case.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
wildeyescommented, Jul 18, 2017

no-use-before-define has an option called nofunc - exactly what I needed.

1reaction
nzakascommented, Sep 25, 2013

Ilya is correct, this is the intended behavior.

Read more comments on GitHub >

github_iconTop Results From Across the Web

For what purpose 'no-use-before-define' warns about declared ...
However, when declaring functions, it is perfectly okay to call a function before it is defined (thanks to the JS hoisting mechanism)
Read more >
no-use-before-define - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Function expression - JavaScript - MDN Web Docs
Function expressions in JavaScript are not hoisted, unlike function declarations. You can't use function expressions before you create them:.
Read more >
When to Use a Function Expression vs. Function Declaration
There are two ways to create functions in JavaScript: function ... Function declarations are hoisted, while function expressions are not.
Read more >
Defending Function Hoisting in a Commit Message - bazile.org
Several of my fellow developers have a preference for using function expressions over named function declarations, e.g.: let add = (a, b) =>...
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