function fun(num){ let num1 = num / 10; let num2 = num % 10; if(num1 < 1){ return num; }else{ num1 = Math.floor(num1); return `${num2}${fun(num1)}`; } } var a = fun(1234) console.log(a); console.log(typeof(a))