{"record":{"id":"fd360161bd1cd64d","repo":"TheAlgorithms/JavaScript","slug":"input-must-be-a-integer-number","errorCode":null,"errorMessage":"Input must be a integer number","messagePattern":"Input must be a integer number","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"Maths/isPalindromeIntegerNumber.js","lineNumber":11,"sourceCode":"/**\n * @function isPalindromeIntegerNumber\n * @param { Number } x\n * @returns {boolean} - input integer is palindrome or not\n *\n * time complexity : O(log_10(N))\n * space complexity : O(1)\n */\nexport function isPalindromeIntegerNumber(x) {\n  if (typeof x !== 'number') {\n    throw new TypeError('Input must be a integer number')\n  }\n  // check x is integer\n  if (!Number.isInteger(x)) {\n    return false\n  }\n\n  // if it has '-' it cannot be palindrome\n  if (x < 0) return false\n\n  // make x reverse\n  let reversed = 0\n  let num = x\n\n  while (num > 0) {\n    const lastDigit = num % 10\n    reversed = reversed * 10 + lastDigit\n    num = Math.floor(num / 10)\n  }","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/TheAlgorithms/JavaScript/blob/5c39e87a9a31f279c60f830ad74a845e4788a517/Maths/isPalindromeIntegerNumber.js#L1-L29","documentation":"Thrown by `isPalindromeIntegerNumber(x)` when `typeof x !== 'number'`. Despite the message saying 'integer', the guard only checks the `number` type - floats pass and are then rejected with a `return false`, not an exception. NaN is typeof 'number' so it slips through and returns false without throwing.","triggerScenarios":"Call `isPalindromeIntegerNumber('121')`, `isPalindromeIntegerNumber(null)`, `isPalindromeIntegerNumber(BigInt(121))`, `isPalindromeIntegerNumber(undefined)`. Floats like `12.1` do NOT throw - they return false.","commonSituations":"URL/form input parsed as string, BigInt from a parser, or a value pulled from JSON where large integers were stringified.","solutions":["Coerce with `Number(x)` and ensure the result is a finite integer before calling.","For string inputs, validate `/^-?\\d+$/` first.","Be aware NaN and floats do not throw - they silently return false - so add an upstream NaN guard if that matters."],"exampleFix":"// before\nisPalindromeIntegerNumber(input) // input may be a string '121'\n\n// after\nconst n = Number(input)\nif (!Number.isInteger(n)) throw new TypeError('input must be an integer')\nisPalindromeIntegerNumber(n)","handlingStrategy":"type-guard","validationCode":"const n = Number(x)\nif (!Number.isInteger(n)) {\n  throw new TypeError('input must be an integer')\n}\nisPalindromeIntegerNumber(n)","typeGuard":"const isIntegerNumber = (x) => typeof x === 'number' && Number.isInteger(x)","tryCatchPattern":null,"preventionTips":["Coerce string input with Number() and check Number.isInteger.","Be aware the function silently returns false for floats and NaN - do not rely on it throwing.","The error message says 'integer' but the throw only checks 'number' - validate stricter upstream."],"tags":["type-validation","math","palindrome","misleading-message"],"backgroundTag":null,"analyzedSha":"5c39e87a9a31f279c60f830ad74a845e4788a517","analyzedAt":"2026-08-13T04:54:54.474Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}