Are JavaScript template literals guaranteed to call toString()?
问题 const num = 42 const str = `My number is ${num}` In this code what guarantee do I have about the conversion of num to a string ? Is it guaranteed to just call its toString() method or could the conversion be done in another way ? 回答1: Untagged templates use the ECMAScript ToString() abstract operation. The logic of template literal evaluation is spread over several sections which makes it difficult to follow, so I'll just post a link to it: https://tc39.es/ecma262/#sec-template-literals