2 ms·
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 optio
by mattigames 4y 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/Reference/Operators/Optional_chaining https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- chii 4y agoGood point. I often forget that there's option chaining in javascript (now-a-days).