ES6の変数は、const
をstrictモードで使用してtry{}
の変数を設定できますか?Javascriptでtryブロック内にconst変数を設定する
'use strict';
const path = require('path');
try
{
const configPath = path.resolve(process.cwd(), config);
}
catch(error)
{
//.....
}
console.log(configPath);
これはconfigPath
がスコープ外に定義されているので、lintの失敗。これが動作しているようです唯一の方法は実行している:基本的に
'use strict';
const path = require('path');
let configPath;
try
{
configPath = path.resolve(process.cwd(), config);
} catch(error)
{
//.....
}
console.log(configPath);
、この場合のためにconst
の代わりlet
を使用することがとにかくありますか?
エラーがスローされた場合、 'console.log(configPath);で何が起こると思いますか? –