Hacker News new | ask | show | jobs
by mattigames 1207 days ago
Given the example I think it is reasonable to assume it is always an string; otherwise if there is any possibility that x is not a string you can just use optional chaining:

     items = items.map(x => x?.toUpperCase() || `<empty>`)
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
1 comments

Good point. I often forget that there's option chaining in javascript (now-a-days).