Cast To String (v8)

Revision 8 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
String Function
var myVar = null,
  newString;
newString = String(myVar);
ready
String Constructor
var myVar = null,
  newString;
newString = new String(myVar);
ready
Concatenate Empty String
var myVar = null,
  newString;
newString = myVar + "";
ready
toString Method
var myVar = null,
  newString;
newString = myVar.toString();
ready
concat if truthy
var myVar = null,
  newString;
newString = myVar ? '' + myVar : '';
ready
concat if truthy or 0
var myVar = null,
  newString;
newString = (myVar || myVar === 0) ? ('' + myVar) : '';
ready
String func on truthy using ||
var myVar = null,
  newString;
newString = String(myVar || '');
ready
concat if truthy using ||
var myVar = undefined,
  newString;
newString = (myVar || '') + '';
ready
concat if truthy using &&
var myVar = undefined,
  newString;
newString = (myVar && '' + myVar) || '';
ready

Revisions

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