Skip to content

use-before-define

Reports a reference that comes before the declaration of what it names in the source (function declarations included), or that runs while the variable is being initialized. References in types are not reported.

A let, const or class read before its declaration fails at run time, and a var is undefined until then. Even where it works (a hoisted function), a reader meets the use before the definition.

To fix, move the declaration above its first use.

Reported
...
before(); function before() {} before2(); var before2 = 1;
const s = s + 1; let t = () => t; class C { static p = C; q = C; } class D extends D {}
for (var i of i) {} const { u = u } = {};
Promise.all([globalThis, hasOwnProperty]);
js:
lint:
rules:
use-before-define:
level: warn # off (default), warn, error
options:
functions: true
classes: true
variables: true
python:
lint:
rules:
use-before-define:
level: warn # off (default), warn, error
options:
functions: true
classes: true
variables: true
Option Type Default Description
functions bool true Check function declarations.
classes bool true Check class declarations.
variables bool true Check var, let and const variables.

Enabled by the presets: js/biome-recommended, python/ruff.

Suppress one line with sudsy-disable-next-line use-before-define in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
eslint no-use-before-define partial the options keep their defaults; JSX tags are not references
ruff F823 full
typescript-eslint no-use-before-define partial the options keep their defaults