Truthiness vs. Length

Benchmark created by Jamie on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="i-exist">test</div>
<script>
  var exists;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Truthy
exists = $('#i-exist').length;
exists = $('#i-dont-exist').length;
ready
Length
exists = $('#i-exist').length>0;
exists = $('#i-dont-exist').length>0;
ready

Revisions

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