title: Why are AngularJS constants editable?
body: <p>I am playing with <a href="https://docs.angularjs.org/guide/providers/#constant-recipe" rel="nofollow noreferrer">AngularJS constants</a>. I am observing that I am able to change the value of the <code>constant</code>s I use. That doesn't make sense. Why I am able to change the value of a <em>constant?</em></p>
  <p>I am creating the constant like this:</p>
  <pre><code>var app = angular.module('app', []);
  app.constant('Type', {
    PNG: 'png',
    GIF: 'gif'
  });
  app.constant('serialId', 'aRandomId');
  </code></pre>
  <p>Even if I create the constant using <code>angular.value</code>, I am still able to change it.</p>
  <p>To change the value of constant I am doing this in my controller:</p>
  <pre><code>app.controller('MainController', [
      '$scope',
      'Type',
      'serialId',
      '$timeout',
  
      function ($scope, Type, serialId, $timeout) {
          $scope.data = {
              type: Type,
              serialId: serialId,
          };
  
          $timeout(function () {
              Type.PNG = 'this is changed';
              serialId = 'new Serial Id';
              console.log(serialId);
          }, 1000);
      },
  ]);
  </code></pre>
  <p>But the definition of &quot;constant&quot; is that what I get <em>is constant</em>. It is something whose value <em>does not change</em> and <em>has a fixed value</em>. <a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/const" rel="nofollow noreferrer">MDN</a> says that once you declare the constant you cannot change it if constant is not an object.</p>
  <p>For example:</p>
  <pre><code>const x=10;
  x=20; //will throw an error.
  
  const obj={};
  obj.a='ab'; //will not throw an error.
  </code></pre>
  <p>But in case of AngularJS constants, nothing prevents me from changing the value. It does not even notify that the value is changed. But their documentation does not talk about changing the value of constants.</p>
  <p><strong>TL;DR: If we can change the value of an AngularJS constant like a plain JavaScript variable then why do they are called constants?</strong></p>
  <p>Here's a <a href="https://jsfiddle.net/hitesh_kumar/ht7mwkrz/" rel="nofollow noreferrer">fiddle</a> to demonstrate.</p>