We need a function that can transform a number into a string.
What ways of achieving this do you know?
numberToString(123); // returns '123';`
numberToString(999); // returns '999';`
function numberToString(num) {
return num.toString();
}
function numberToString(num) {
return String(num);
}
Note: String(value) vs value.toString()
value.ToString()
will cause error if value isnull
orundefined
String(value)
mostly works likevalue + ''
function numberToString(num) {
return num + '';
}
function numberToString(num) {
return '' + num;
}
Note: concatenation
- Aything concatenated with string will coerced to string
const numberToString = num => `${num}`;