| **Scope** | <div><p>If an exported value changes in the module it was defined in, that change is visible in all modules that import this value.<p>For example: <pre><code>// somefile.js let count = 1; export { count }; setTimeout(() => count = 2, 1000);</code></pre> Now use it somewhere <pre><code>// main.js import { count } from './somefile.js'; console.log(count); // 1 setTimeout(() => console.log(count), 1000); // 2</code></pre></div> | <div><p>The exports are _copied_ at the time of requiring the module.<br>So even if an exported value changes in the module it was defined in, that change is **not** visible in the module where it's required.</p> For example: <pre><code>// somefile.js let count = 1; module.exports.count = count; setTimeout(() => count = 2, 1000);</code></pre> Now use it somewhere <pre><code>// main.js const mod = require('./somefile.js'); console.log(mod.count); // 1 setTimeout(() => console.log(mod.count), 1000); // 1</code></pre></div> |