Bool to string conversion

Benchmark created on


Description

Consider a boolean: abool. And I want to convert it to string.

  1. abool ? "true" : "false";
  2. abool.toString();
  3. ${abool};

Which one is better and why?

Test runner

Ready to run.

Testing in
TestOps/sec
Ternary expression
const abool = Math.random() < 0.5;
abool ? "true" : "false";
ready
toString()
const abool = Math.random() < 0.5;
abool.toString();
ready
Template literal
const abool = Math.random() < 0.5;
`${abool}`;
ready

Revisions

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