{"record":{"id":"95c5625a0017bcce","repo":"TheAlgorithms/JavaScript","slug":"argument-is-not-a-number-95c562","errorCode":null,"errorMessage":"Argument is not a number.","messagePattern":"Argument is not a number\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"Maths/ReverseNumber.js","lineNumber":13,"sourceCode":"/*\n    Problem statement and Explanation : https://medium.com/@ManBearPigCode/how-to-reverse-a-number-mathematically-97c556626ec6\n*/\n\n/**\n * ReverseNumber return the reversed value of the given number.\n * @param {Number} n any digit number.\n * @returns `Number` n reverse in reverse.\n */\nconst ReverseNumber = (number) => {\n  // firstly, check that input is a number or not.\n  if (typeof number !== 'number') {\n    throw new TypeError('Argument is not a number.')\n  }\n  // A variable for storing the reversed number.\n  let reverseNumber = 0\n  // Iterate the process until getting the number is 0.\n  while (number > 0) {\n    // get the last digit of the number\n    const lastDigit = number % 10\n    // add to the last digit to in reverseNumber\n    reverseNumber = reverseNumber * 10 + lastDigit\n    // reduce the actual number.\n    number = Math.floor(number / 10)\n  }\n  return reverseNumber\n}\n\nexport { ReverseNumber }\n","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/TheAlgorithms/JavaScript/blob/5c39e87a9a31f279c60f830ad74a845e4788a517/Maths/ReverseNumber.js#L1-L30","documentation":"The ReverseNumber function reverses the digits of a number mathematically using modulo and division. The guard rejects non-number types because the arithmetic would fail or coerce incorrectly. Important caveat: the function only handles positive numbers (the while loop checks number > 0), so negative numbers silently return 0 without error.","triggerScenarios":"Calling ReverseNumber(\"123\"), ReverseNumber(null), or ReverseNumber([1,2,3]). Any non-number type triggers this error.","commonSituations":"String numbers from HTML form inputs, parsed JSON, CLI arguments, or values extracted from Maps/Sets that lost their type.","solutions":["Pass a number primitive to ReverseNumber.","Parse strings with Number() or parseInt() before calling.","Be aware that negative numbers silently return 0; handle the sign separately."],"exampleFix":"// before\nReverseNumber(inputEl.value) // inputEl.value is a string\n// after\nReverseNumber(Number(inputEl.value))","handlingStrategy":"type-guard","validationCode":"if (typeof number !== 'number') {\n  throw new TypeError('Argument must be a number')\n}\nReverseNumber(number)","typeGuard":"const isNonNegativeNumber = (n) => typeof n === 'number' && n >= 0","tryCatchPattern":null,"preventionTips":["Parse strings to Number() before reversing digits.","Handle negative numbers separately since the function silently returns 0 for negatives.","Validate input type at API boundaries where external data enters."],"tags":["math","type-check","input-validation","number-manipulation"],"backgroundTag":null,"analyzedSha":"5c39e87a9a31f279c60f830ad74a845e4788a517","analyzedAt":"2026-08-13T04:54:54.474Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}