LET vs VAR vs CONST in for loops

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
CONST
const s = "I am a test string";
const t = "I am 2nd test string";

let count = 0;
const map = {}
for (const c of s) {
	if (!map[c]) {
		map[c] = 1;
	} else {
		map[c] += 1
	}
}
for (const c of t) {
	if (map[c]) {
		map[c] -= 1
	} else {
		count++
	}
}


ready
LET
const s = "I am a test string";
const t = "I am 2nd test string";

let count = 0;
const map = {}
for (let c of s) {
	if (!map[c]) {
		map[c] = 1;
	} else {
		map[c] += 1
	}
}
for (let c of t) {
	if (map[c]) {
		map[c] -= 1
	} else {
		count++
	}
}

ready
VAR
const s = "I am a test string";
const t = "I am 2nd test string";

let count = 0;
const map = {}
for (var c of s) {
	if (!map[c]) {
		map[c] = 1;
	} else {
		map[c] += 1
	}
}
for (var c of t) {
	if (map[c]) {
		map[c] -= 1
	} else {
		count++
	}
}

ready

Revisions

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