"Type of undefined" vs "=== undefined" (v71)

Revision 71 of this benchmark created by Fuwei Chin on


Description

This undefined-check test covers 6 ECMAScript types(number,string,boolean,object,function,undefined) and 2 accessing methods(via variables or properties).

Note: each var/prop name was kept the same length in order to reduce the time-spent difference in map retrieving.

Setup

//truthy variables in distinct types
    var a=1, b=true, c="c", d={}, e=function(){};
    //falsy variables in distinct types
    var h=0, i=false, j="", k=null, l=undefined;
    //object-properties mirror of scope-variables above
    var o={
      a:1, b:true, c:"c", d:{}, e:function(){},
      h:0, i:false, j:"", k:null, l:undefined
    };
    //local undefined
    var u=undefined;

Test runner

Ready to run.

Testing in
TestOps/sec
typeof undefined
typeof a === 'undefined';
typeof b === 'undefined';
typeof c === 'undefined';
typeof d === 'undefined';
typeof e === 'undefined';

typeof h === 'undefined';
typeof i === 'undefined';
typeof j === 'undefined';
typeof k === 'undefined';
typeof k === 'undefined';

typeof o.a === 'undefined';
typeof o.b === 'undefined';
typeof o.c === 'undefined';
typeof o.d === 'undefined';
typeof o.e === 'undefined';

typeof o.h === 'undefined';
typeof o.i === 'undefined';
typeof o.j === 'undefined';
typeof o.k === 'undefined';
typeof o.l === 'undefined';
ready
=== undefined (global)
a === undefined;
b === undefined;
c === undefined;
d === undefined;
e === undefined;

h === undefined;
i === undefined;
j === undefined;
k === undefined;
l === undefined;

o.a === undefined;
o.b === undefined;
o.c === undefined;
o.d === undefined;
o.e === undefined;

o.h === undefined;
o.i === undefined;
o.j === undefined;
o.k === undefined;
o.l === undefined;
ready
=== undefined (local)
a === u;
b === u;
c === u;
d === u;
e === u;

h === u;
i === u;
j === u;
k === u;
l === u;

o.a === u;
o.b === u;
o.c === u;
o.d === u;
o.e === u;

o.h === u;
o.i === u;
o.j === u;
o.k === u;
o.l === u;
ready
=== void 0
a === void 0;
b === void 0;
c === void 0;
d === void 0;
e === void 0;

h === void 0;
i === void 0;
j === void 0;
k === void 0;
l === void 0;

o.a === void 0;
o.b === void 0;
o.c === void 0;
o.d === void 0;
o.e === void 0;

o.h === void 0;
o.i === void 0;
o.j === void 0;
o.k === void 0;
o.l === void 0;
ready

Revisions

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