HomeProjects
 
  
🔍

Arrays passed to template literals get coerced to strings

December 4, 2020

Nice little thing I learned today: When you pass an Array as a value to a template literal, it gets implicitly coerced into a String. Behind the scenes String.prototype.concat is used, as stated in the ECMA-262 specification document.

const fruits = ['apples', 'oranges'];
console.log(`${fruits}`); // 'apples,oranges'

 

© 2021. Made with ♡ by me :)