Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Var vs Let
(version: 0)
Just a simple test with var/let performance in for loop
Comparing performance of:
var vs let
Created:
9 years ago
by:
Guest
Jump to the latest result
Tests:
var
for(var i=1;i<=1000;i++) console.log(i);
let
for(let i=1;i<=1000;i++) console.log(i);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
var
let
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.3 Mobile/15E148 Safari/604.1
Browser/OS:
Mobile Safari 26 on iOS 18.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
var
2802.0 Ops/sec
let
2610.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested. **Overview** The benchmark measures the performance difference between using `var` and `let` variables in a for loop, specifically logging numbers from 1 to 1000. The test is designed to evaluate which approach (variable scope) results in faster execution. **Variables: Var vs Let** In JavaScript, both `var` and `let` are used as variable declarations, but they behave differently when it comes to scoping: * **Var**: Variables declared with `var` have function scope, not block scope. This means that a single variable declaration can affect variables from outer scopes within the same function. * **Let**: Variables declared with `let` have block scope, which means each variable is scoped to its own block (e.g., if statement, loop, or switch). This provides better isolation and avoids polluting the global scope. **Performance Comparison** The test compares the performance of two code snippets: 1. Using `var` for loop: ```javascript for(var i=1;i<=1000;i++) console.log(i); ``` 2. Using `let` for loop: ```javascript for(let i=1;i<=1000;i++) console.log(i); ``` **Pros and Cons** * **Var**: The main advantage of using `var` is that it might be faster in older browsers or environments where `let` support was not yet implemented. However, this comes at the cost of potential variable scope issues. * **Let**: Using `let` provides better code maintainability, as variables are isolated and less likely to pollute outer scopes. In most modern JavaScript environments, `let` is preferred over `var` due to its block scope behavior. **Special JS Features/Syntax** There's no special feature or syntax being tested in this benchmark. It solely focuses on comparing the performance of `var` vs `let`. **Other Alternatives** If you want to explore more JavaScript performance benchmarks, here are some alternatives: * MeasureThat.net: Offers various benchmarks for JavaScript engines. * Browser Benchmark: Provides a range of browser-specific benchmarks. * jsperf (now archived): Was an older benchmarking platform that compared different aspects of JavaScript. Keep in mind that benchmarking results may vary depending on the specific environment, hardware, and JavaScript engine used. Always verify results with multiple tests and sources to ensure accuracy.
Related benchmarks:
var vs. const vs. let
let vs var for loop
let vs const in tight loops
var vs const vs let
Comments
Confirm delete:
Do you really want to delete benchmark?