no-redeclare

禁止变量重新声明

配置文件 中的 "extends": "eslint:recommended" 属性启用了该规则

在 JavaScript 中,可以使用 var 重新声明相同的变量名。这可能会导致混淆变量的实际声明和初始化位置。

规则详情

此规则旨在消除在同一范围内具有多个声明的变量。

此规则的错误代码示例:

/*eslint no-redeclare: "error"*/

var a = 3;
var a = 10;

class C {
    foo() {
        var b = 3;
        var b = 10;
    }

    static {
        var c = 3;
        var c = 10;
    }
}

f/g6SKVZdhoBiPVtnee0m+uPEv1T4kMgIaFUpxdtFwzAZHGBqJ5dJxRHxHHP/cP8

/*eslint no-redeclare: "error"*/

var a = 3;
a = 10;

class C {
    foo() {
        var b = 3;
        b = 10;
    }

    static {
        var c = 3;
        c = 10;
    }
}

选项

vWW8bjzeIqHfVD0xuzQnY07o71Gxrj/F7KhCR3cPpSY4dgVR08OrlmMQGHKNq0DJkmc3PkFwtVwYsPhuz7IgDb7ou8ypiI/GQR4L0GKLBztb4qn5l4XBiWbfNflXu++ypld4g8B9OhdGTAOmGgj7bea5WZmoM05ih1P/agSoB2WLcgH67uisNXG8aYPjOG2LwYVLhtMOsOAPH+ZHYZn1UssQUvQi+DlVhAMDJuaX6QNilFemsbz2IdGZLd+I9WHX7NjEwOWSsPtmpSdZzyJ3vlStW10lVarS42fpsfBl75kXgS1rbgonjPoo4n3qSPI7WRi7hyXAc6xp1i0RpQ2fou69DxAZUkOfji9/J6XWaK7Dgg3rqw8uNC45cFvCLJag2/SzxW0gYJFNtwk/C2IVmA==

builtinGlobals

ylEGhXgNbddMdkxlVmI72m2GVxbqG9/342bcf2hB2j3R6g5F4giZMcS5vonNnoxbNhVzYBLEgzr8iE++zKp6jNjc2rMduZpv5Q7v4izbFLhH68sdDMlUvyx0lZMVD7uscRFiqjIUgn0GHtIaiuYSlw==

PKOGP9hFQNOtwPmG1U0c5fvao66pX60ITxkbAm8I8ZW0PIz0b6r0S17HuMxK5tPfcNSLTnkPAEv+EgtJVgpfRtLSVTnqAYLL4f+ofOsDSf4=

/*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/

var Object = 0;

PKOGP9hFQNOtwPmG1U0c5fvao66pX60ITxkbAm8I8ZV+9yHp7Niz1WOnqZBRTGgKfu5dqtLwcrFm3rxWjVjxDh/1P6lVKN2+t9zMdSVgVCFDpDEW8E8412+ZYBpp1YFWFv/G19C9z1DIT6hr+/Pyug==

/*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/
/*eslint-env browser*/

var top = 0;

8N564mAmL4Bi/YDTI+6jsO1QTiPHy2so8No34skQECx5HbBrCHMHoeRmrQ3LPvy7uQ0hIv2ud7XIwAqFRiyRdF2lvxrCDub1E6KeMwC/sD3bUHB8XAGpsWFkbxBVe5g/b0Ug5DfrqtAUNVdw9gGxhuEYj4X/6h7yPm7lyD1Qbl4SC3/kkfrsQdYSA8qfWqHq

4x4C+JTeHfAG7tizHKnqr+a/oHUoTiu3zDmu+nmFtvYntVM/Tu+Uoz93gtS6Zon1qbkRdRZdYiuegfvZnA4DYGIhpt1R6CLMTCbGyIgpeTGmbVXhHDdfhLOnO8x61YozHvA0ZRkz0an3k3nSuczOjWD3AoWHLlRngUZcNz/sQPE7oUXAcqbiVDFhKLxzQqM1fhh7VthgV/m1zrwj/07CvweHywfrjHXtsBci3YAK+cFAh1eEG9XDzh82X2qwi3n9Fznkl58+D7VawSvtvYR3Rz1EZrMFbMWsSUzXenUyMv7oI0vqfw9X50Ug/iLRmouWNl6wdac2a5fHN7q8GKASDnYwSmLi17slns0I3o5igUpy8E3WL5gkNxtQPmGLIpeEo/h3BKpVacvA//cgThsna/7JoacCTJod4C7fnOJVqMHFeDtaBRpaFaX4M2nRaXQI9/4jVdLevngBO2ek2wjwkVnChZgzFlfvHBl56gzony+XHluRM41O0mgAph0TPFguPQeDgWbA8UTXs9wxcLuUNklc4TsVTQbh7WG5jC2Qyx3pHLVWS5Nvbv4jpJ+DbSjLD5tJ3bHipLEI2xCrjt7jV4SOt8Ji5peohvZ+sac78MSRLgBKyyJxSvQOje8wl0DTZvwS+YPCVexlV8/68yPie//sjBX1It6VwG+cJsp6bgY=