javascript - Why does `var exports = module.exports = {};` works but not `let exports = module.exports = {};`? -


during code optimisation of project, replacing instances of var keyword let because think there no particular use left var. did 'find & replace' in files this.

in custom modules had used statements like:

var exports = module.exports = {}; 

which worked fine.

now, after replacing let, became:

let exports = module.exports = {}; 

it not work , gives error

syntaxerror: identifier 'exports' has been declared

though can use var , avoid problem, still want know reason behind this.

edit: have not used let exports = <something>; anywhere in same module file. statement have declared exports variable.

the reason because exports initialized in nodejs module system.

https://nodejs.org/api/modules.html#modules_module_exports

the object exists, module.exports when module loads. since let scope specific preventing limiting scope. const fail.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -