DoubleExclamationPoints

Benchmark created by Marc on


Description

foo = foo || {}; vs foo = !!foo ? foo : {};

Setup

var simpleString = 'foo';
    var PJO = { bar: 'bar' };
    var simpleArray = [1, 2, 3];
    var simpleEmpty;
    var simpleTrue = true;
    var simpleFalse = false;

Test runner

Ready to run.

Testing in
TestOps/sec
OR - string
var result = simpleString || '';
ready
OR - PJO
var result = PJO || {};
ready
OR - Array
var result = simpleArray || [];
ready
OR - Empty
var result = simpleEmpty || {};
ready
OR - boolean true
var result = simpleTrue || true;
ready
OR - boolean false
var result = simpleFalse || false;
ready
Exclamation - string
var result = !!simpleString ? simpleString : "";
ready
Exclamation - PJO
var result = !!PJO ? PJO : {};
ready
Exclamation - Array
var result = !!simpleArray ? simpleArray : [];
ready
Exclamation - undefined
var result = !!simpleEmpty ? simpleEmpty : true;
ready
Exclamation - boolean true
var result = !!simpleTrue ? simpleTrue : true;
ready
Exclamation - boolean false
var result = !!simpleFalse ? simpleFalse : true;
ready

Revisions

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