title: Why is TypeScript generating an IIFE for a namespace?
body: <p>I have this TS code:</p>
  <pre><code>export namespace Constants
  {
      export var x = 0;        
  }
  </code></pre>
  <p>If I compile it with 'tsc' I get this JS code:</p>
  <pre><code>&quot;use strict&quot;;
  exports.__esModule = true;
  exports.Constants = void 0;
  
  var Constants;
  (function (Constants) {
      Constants.x = 0;
  })(Constants = exports.Constants || (exports.Constants = {}));
  </code></pre>
  <p>My question is. Why 'tsc' compiles a namespace into an IIFE instead of a simple and much more readable object like this?</p>
  <pre><code>var Constants = {};
  Constants.x = 0;
  </code></pre>
  <p>Is there any particular reason?</p>
  <p>There are <a href="https://stackoverflow.com/questions/1335851/what-does-use-strict-do-in-javascript-and-what-is-the-reasoning-behind-it">other questions similar</a> to this. Except that they don't give any true answer. What makes this question different is that a namespace is meant to be only a simple container to segregate code, then it must be as simple and readable as possible and an IIFE isn't the best solution to do that.</p>