// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
\page qmllint-warnings-and-errors-var-used-before-declaration.html
\ingroup qmllint-warnings-and-errors

\title Var used before declaration
\brief A JavaScript variable was used before its declaration.

\qmllintwarningcategory var-used-before-declaration

\section1 Variable is used here before its declaration

\section2 What happened?
You used a variable before you declared it.

\sa {JavaScript Expressions in QML Documents}

\section2 Why is this bad?
This makes the code harder to read. Variables declared with
\c let or \c const will error out at runtime.

\section2 Example
\qml
import QtQuick

Item {
    function f() {
        x = 42; // x is used before its declaration
        let x;
    }

    Component.onCompleted: f()
}
\endqml
To fix this warning, move the declaration before the usage:
\qml
import QtQuick

Item {
    function f() {
        let x;
        x = 42;
    }

    Component.onCompleted: f()
}
\endqml
*/

