JavaScript Performance: Variable Initialization
2 Aug 2014 • 2 minute readInitializing variables properly in JavaScript can have significant performance benefits. This can be shown with a simple synthetic benchmark.
notype.js
var x = null;
for (var i = 0; i < 1e8; i++) {
x = 1 + x;
}
withtype.js
var x = 0;
for (var i = 0; i < 1e8; i++) {
x = 1 + x;
}