reverse a number javasript code example

Example 1: reverse number javascript

// Function to reverse Number
function reverseNum(n) {
  let r = n.toString().split('').reverse().join('');
  return Math.sign(n) * parseInt(r);
}

// Call
reverseNum(-267);
reverseNum(31522);

// Outputs
-762
22513

Example 2: reverse int js

function reverseInt(n) {
  const reversed = n.toString().split("").reverse().join(""); 

  return parseInt(reversed) * Math.sign(n);
}

Example 3: js reverse number

const reversedNum = num => parseFloat(num.toString().split('').reverse().join('')) * Math.sign(num)

Tags:

Misc Example