Boolean vs true false vs 1 0
JavaScript performance comparison
Info
Which works faster (is there a difference), using Boolean(), true/false, !!, or 1/0?
Preparation code
<script>
Benchmark.prototype.setup = function() {
var booleanTrue = Boolean(1);
var booleanFalse = Boolean(0);
var trueTrue = true;
var falseFalse = false;
var numTrue = 1;
var numFalse = 0;
var exTrue = !0;
var exFalse = !1;
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Boolean() |
|
pending… |
!! |
|
pending… |
true/false |
|
pending… |
One Zero |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published by Kyle A. Matheny
- Revision 2: published
- Revision 7: published by Ian Nartowicz
- Revision 8: published by pkoretic
- Revision 9: published by Aaron Gloege
0 comments