undefined (v13)

Revision 13 of this benchmark created by Anders Ringqvist on


Description

Pitfalls:

  1. One should know that it´s not safe to use the global variable undefined as it is writeable before ES5.

  2. This actually checks if x is falsy.

Setup

var x;

Test runner

Ready to run.

Testing in
TestOps/sec
x === undefined (1)
x === undefined

/* See 1. in Description */
ready
typeof x === 'undefined'
typeof x === 'undefined'
ready
x === void 0
x === void 0
ready
!x (2)
!x

/* See 2. in Description */
ready
null
x == null
ready
[][0]
x === [][0]
ready
{}.x
x === {}.x
ready
x == undefined (1)
x == undefined

/* See 1. in Description */
ready
typeof x == 'undefined'
typeof x == 'undefined'
ready
'undefined' == '' + x
'undefined' == '' + x
ready
'undefined' === '' + x
'undefined' === '' + x
ready

Revisions

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