在ES6中是否可以在严格模式下try{}使用变量const?
'use strict';
const path = require('path');
try
{
const configPath = path.resolve(process.cwd(), config);
}
catch(error)
{
//.....
}
console.log(configPath);
Run Code Online (Sandbox Code Playgroud)
这不能lint因为configPath在范围之外定义.这似乎有用的唯一方法是:
'use strict';
const path = require('path');
let configPath;
try
{
configPath = path.resolve(process.cwd(), config);
} catch(error)
{
//.....
}
console.log(configPath);
Run Code Online (Sandbox Code Playgroud)
基本上,无论如何使用const而不是let这种情况?