在 catch 子句中声明 e 变量的正确方法是什么

What is the correct way to declare the e variable in a catch clause

当我没有声明 catch 用来存储错误的变量时,JSHint 给我以下错误

function foo (){
    try{
        let a = 0/0;
    } catch (e){
        console.log (e);
    }
}

error| 'e' is not defined

当我定义它时,我得到了这个错误

function foo (){
    let e;

    try{
        let a = 0/0;
    } catch (e){
        console.log (e);
    }
}

error| Value of 'e' may be overwritten in IE8 and earlier

是否有声明 e 的最佳实践方法?如果没有,我该如何抑制这个 JSHint 错误?

MDN try...catch 文档中描述的 exception_var 不需要初始化。此变量的处理方式类似于函数的参数:catch(e) 中的定义创建引用。

JSHint 是正确的,因为在 try/catch 语句之外初始化 exception_var(许多开发人员将其用作 e/err)可能会导致不需要的行为。