- Takes any value
- Returns a string
It'll take a boolean
, a number
, null
, undefined
, an Array
, an Error
,
an object
, even another string
!
const unknowns = [
true,
false,
123,
null,
undefined,
['Hello', 'world'],
new Error('test error message'),
{ Hello: 'world' },
'string',
];
const strings = unknowns.map(mapUnknownToString);
console.log(strings);
/*
[
'true',
'false',
'123',
'null',
'undefined',
'["Hello", "world"]',
'test error message',
'{"Hello": "world"}',
'string',
]
*/