Description
- We need a function that can transform a number into a string.
Solution 01
function numberToString(num) {
return '' + num;
}
numberToString(1234); // 1234
console.log(typeof numberToString(1234)); // string
Solution 02
function numberToString(num) {
return num.toString();
}
numberToString(1234); // 1234
console.log(typeof numberToString(1234)); // string
Solution 03
function numberToString(num) {
return String(num);
}
numberToString(1234); // 1234
console.log(typeof numberToString(1234)); // string