hasOwnProperty vs in vs undefined (v44)

Revision 44 of this benchmark created on


Description

A variant of http://jsperf.com/hasownproperty-vs-in-vs-undefined/12 just without the "var undefined" in the test code. This changes the picture for all the "undefined" dependent tests.

Setup

var Iobj = {
      SUPPORT_ACTIONS: 0x1
    };
    var obj = {
      actions: true,
      support: Iobj.SUPPORT_ACTIONS
    };
    var foo = "actions";

Test runner

Ready to run.

Testing in
TestOps/sec
hasOwnProperty
if (obj.hasOwnProperty("actions")) {
  return true;
}
ready
in
if ("actions" in obj) {
  return true;
}
ready
undefined
if (typeof obj.actions !== 'undefined') {
  return true;
}
ready
undefined cmp
if (obj.actions !== undefined) {
  return true;
}
ready
var in
if (foo in obj) {
  return true;
}
ready
undefined cmp (dynamic)
if (obj['actions'] !== undefined) {
  return true;
}
ready
undefined dynamic
if (typeof obj['actions'] !== 'undefined') {
  return true;
}
ready
truthy
if (obj.actions) {
  return true;
}
ready
null
if (obj.actions != null) {
  return true;
}
ready
falsey
if (!obj.actions) {
  return true;
}
ready
falsey dynamic
if (!obj["actions"]) {
  return true;
}
 
ready
falsey var
if (!obj[foo]) {
  return true;
}
 
ready

Revisions

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