Why "use strict" improves performance 10x in this example?
<p>Following the question <a href="https://stackoverflow.com/questions/38407760/extending-string-prototype-performance-shows-that-function-calls-are-10x-faster">Extending String.prototype performance</a> I am really intrigued, because just adding <code>"use strict"</code> to a <code>String.prototype</code> method improved performance 10 times. The <a href="https://stackoverflow.com/a/38410199/1968972">explanation</a> by <a href="https://stackoverflow.com/users/1048572/bergi">bergi</a> is short and does not explain it to me. Why there is such a dramatic difference between two almost identical methods, that only differ in <code>"use strict"</code> at the top? Can you explain in more detail and with the theory behind this?</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>String.prototype.count = function(char) {
  var n = 0;
  for (var i = 0; i &lt; this.length; i++)
    if (this[i] == char) n++;
  return n;
};

String.prototype.count_strict = function(char) {
  "use strict";
  var n = 0;
  for (var i = 0; i &lt; this.length; i++)
    if (this[i] == char) n++;
  return n;
};
// Here is how I measued speed, using Node.js 6.1.0

var STR = '0110101110010110100111010011101010101111110001010110010101011101101010101010111111000';
var REP = 1e4;

console.time('proto');
for (var i = 0; i &lt; REP; i++) STR.count('1');
console.timeEnd('proto');

console.time('proto-strict');
for (var i = 0; i &lt; REP; i++) STR.count_strict('1');
console.timeEnd('proto-strict');</code></pre>
</div>
</div>
</p>

<p>Result:</p>

<pre><code>proto: 101 ms
proto-strict: 7.5 ms
</code></pre>