Javascript set const variable inside of a try block

前端 未结 4 1682
故里飘歌
故里飘歌 2020-12-09 02:13

Is it possible in ES6 to set a variable inside of a try{} using const in strict mode?

\'use strict\';

const path          


        
4条回答
  •  难免孤独
    2020-12-09 02:33

    'use strict';
    
    const path = require('path');
    
    const configPath = (function() {
      try {
        return path.resolve(process.cwd(), config);
      } catch (error) {
        //.....
      }
    })()
    
    console.log(configPath);
    

提交回复
热议问题