선언 전에 사용된 변수

이 경고 카테고리의 철자는 [var-used-before-declaration] 입니다.

변수가 선언 전에 사용되었습니다.

무슨 일이 일어났나요?

변수를 선언하기 전에 변수를 사용했습니다.

이것이 왜 나쁜가요?

코드를 읽기 어렵게 만듭니다. let 또는 const 로 선언된 변수는 런타임에 오류가 발생합니다.

예제

import QtQuick

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

    Component.onCompleted: f()
}

이 경고를 수정하려면 선언을 사용 전으로 옮기세요:

import QtQuick

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

    Component.onCompleted: f()
}

QML 문서의 자바스크립트 표현식을참조하세요 .

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.