baseToString
Before we go for conversion, we can first try
typeof value. If it returns string then we don't have to do any conversion.
If the value is array then we need to convert each of its value to its string form.
if (Array.isArray(value)) {
return `${value.map(baseToString)}`
}
If it is a symbol then we need to convert it to symbol's toString.
console.log(Symbol.prototype.toString.call(Symbol.toStringTag))Output:
Symbol(Symbol.toStringTag)Anything else we just need to parse.
const value = true
console.log(`${value}`)
Output:
true
Comments
Post a Comment