Observing strange behavior in my map function:
let tpl = ({x}, y = `This is ${x}`) => y;
console.log( tpl({x:5}) ); //correctly returns 'This is 5'
console.log( [{x:1}, {x:9}].map(tpl) ); //expecting array of strings, instead get [0, 1]
It is possible to 'fix' this by omitting default variable y, and returning the template string directly from tpl. However, I would prefer to do the initialization this way and can't understand why it wouldn't still work.
Seems like a strange anomaly to me, does someone have insight on something I am missing?
ywhen you can just return the template string directly like you said? Is it because you are sometimes passing in an optional template string to override the default one?