Determine whether a value is an object or primitive

Benchmark created on


Setup

const protoLess = Object.create(null)

Test runner

Ready to run.

Testing in
TestOps/sec
`instanceof`
((value) => {
  if (value instanceof Object) return true;

  if (value === null || value === undefined)
    return false;

  return Object.getPrototypeOf(value) === null
})(protoLess)
ready
`typeof`
((value) => {
  return value !== null && (
    typeof value === 'function' ||
    typeof value === 'object'
  )
})(protoLess)
ready

Revisions

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