Please note that new String() is a wrong and dangerous answer as it returns a String object and not a string. Much better is the String() static method, that just calls .toString() on the argument.
{constobj={toString:()=>"YOWZA",valueOf:Math.random}letaconstexamples=`String(0)
new String(0)
typeof String(0)
typeof new String(0)
!!String("")
!!new String("")
String(0)==="0"
new String(0)==="0"
String(obj)
new String(obj)
Number("0")
new Number("0")
typeof Number("0")
typeof new Number("0")
!!Number("0")
!!new Number("0")
Number("0") === 0
new Number("0") === 0
Number(obj)
new Number(obj)
Boolean(false)
new Boolean(false)
typeof Boolean(false)
typeof new Boolean(false)
!!Boolean(false)
!!new Boolean(false)
(a = Number(), a.b=a, a.b)
(a = new Number(), a.b=a, a.b)`.split('\n')constmaxLen=Math.max(...examples.map(x=>x.length))examples.forEach(line=>console.log(line.padEnd(maxLen)," => ",eval(line)))}
Above are just a few examples of how this will get you.
Please note that
new String()
is a wrong and dangerous answer as it returns aString
object and not astring
. Much better is theString()
static method, that just calls.toString()
on the argument.Above are just a few examples of how this will get you.
Or, non-executably: