variables inside functions

JavaScript performance comparison

Test case created by Sukima


Is it better scope variables inside or outside a looped function?

Preparation code

<script src=""></script>
Benchmark.prototype.setup = function() {
    var outer_scoped, sample = new Array(10000);

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
outer scoped
_.each(sample, function(v, i) {
  outer_scoped = "this is a test";
  sample[i] = outer_scoped.toUpperCase();
inner scoped
_.each(sample, function(v, i) {
  var inner_scoped = "this is a test";
  sample[i] = inner_scoped.toUpperCase();

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers


Comment form temporarily disabled.

Add a comment