''+num is a way to convert a number to its string representation. If you want an explanation of what the code is doing -- see the comments, as they are numbered.
let x = (function squareDigits(num) {
return Number( // 5. This is redundant. Result of 4 was already a number. But it returns the result.
('' + num) // 1. Converts number to string eg. 123 => "123"
.split('') // 2. Coverts the string to an array eg. "123" => ["1", "2", "3"]
.map(function (val) {
// 3. Returns an array by mapping eg. ["1", "2", "3"] => [1, 4, 9]
return val * val; // note: * operator coerces string digits to numbers
})
.join('') // 4. Joins the array eg. [1, 4, 9] => 149
);
})(somenumber);
''+numis a way to cast a Number to a String. You could also usenum.toString()if you prefer. Note that+stringcasts a String to a Number, as well.