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

Revision 33 of this benchmark created on


Preparation HTML

<script>
function typeOf(v) {
      return typeof v === "undefined";
}

function typeOfNonStrict(v) {
      return typeof v == "undefined";
}

function void0(v) {
      return v === void 0;
}

function globalUndefined(v) {
      return v === undefined;
}
var a = 1,
  b = true,
  c = "c",
  d = [],
  e = {}, u;
var l = 10000;

while(l--) {
if (typeOf(a) ) {
    throw new Error("");
}
if (typeOf(b) ) {
    throw new Error("");
}
if (typeOf(c) ) {
    throw new Error("");
}
if (typeOf(d) ) {
    throw new Error("");
}
if (typeOf(e) ) {
    throw new Error("");
}

if (globalUndefined(a) ) {
    throw new Error("");
}
if (globalUndefined(b) ) {
    throw new Error("");
}
if (globalUndefined(c) ) {
    throw new Error("");
}
if (globalUndefined(d) ) {
    throw new Error("");
}
if (globalUndefined(e) ) {
    throw new Error("");
}

if (void0(a) ) {
    throw new Error("");
}
if (void0(b) ) {
    throw new Error("");
}
if (void0(c) ) {
    throw new Error("");
}
if (void0(d) ) {
    throw new Error("");
}
if (void0(e) ) {
    throw new Error("");
}

if (typeOfNonStrict(a) ) {
    throw new Error("");
}
if (typeOfNonStrict(b) ) {
    throw new Error("");
}
if (typeOfNonStrict(c) ) {
    throw new Error("");
}
if (typeOfNonStrict(d) ) {
    throw new Error("");
}
if (typeOfNonStrict(e) ) {
    throw new Error("");
}
}

</script>

Setup

var a = 1,
      b = true,
      c = "c",
      d = [],
      e = {}, u;

Test runner

Ready to run.

Testing in
TestOps/sec
typeof undefined
if (typeOf(a) ) {
    throw new Error("");
}
if (typeOf(b) ) {
    throw new Error("");
}
if (typeOf(c) ) {
    throw new Error("");
}
if (typeOf(d) ) {
    throw new Error("");
}
if (typeOf(e) ) {
    throw new Error("");
}
ready
=== undefined
if (globalUndefined(a) ) {
    throw new Error("");
}
if (globalUndefined(b) ) {
    throw new Error("");
}
if (globalUndefined(c) ) {
    throw new Error("");
}
if (globalUndefined(d) ) {
    throw new Error("");
}
if (globalUndefined(e) ) {
    throw new Error("");
}
ready
=== undefined(local)
a === u;
b === u;
c === u;
d === u;
e === u;
ready
void 0
if (void0(a) ) {
    throw new Error("");
}
if (void0(b) ) {
    throw new Error("");
}
if (void0(c) ) {
    throw new Error("");
}
if (void0(d) ) {
    throw new Error("");
}
if (void0(e) ) {
    throw new Error("");
}
ready
typeof ==
if (typeOfNonStrict(a) ) {
    throw new Error("");
}
if (typeOfNonStrict(b) ) {
    throw new Error("");
}
if (typeOfNonStrict(c) ) {
    throw new Error("");
}
if (typeOfNonStrict(d) ) {
    throw new Error("");
}
if (typeOfNonStrict(e) ) {
    throw new Error("");
}
ready

Revisions

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