Short int check vs trad int check

Benchmark created by Maarten Jacobs on


In the underscore.js library, specifically the very first function called forEach (alias for each), a test is made to check if the length property of the given object is an integer. The way it does this is not the traditional typeof check, but by using the plus operator

Preparation HTML

  var foo = [];

Test runner

Ready to run.

Testing in
Traditional number check
if(typeof foo.length === 'number'){
console.log('It be a number, Batman!');
Plus operator number check
if(foo.length === +foo.length){
console.log('It be a number, Batman!');


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

  • Revision 1: published by Maarten Jacobs on