{"record":{"id":"3079066181f0ca02","repo":"TheAlgorithms/JavaScript","slug":"the-given-value-is-not-a-string","errorCode":null,"errorMessage":"The given value is not a string","messagePattern":"The given value is not a string","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"String/CheckPangram.js","lineNumber":16,"sourceCode":"/**\n * What is Pangram?\n * Pangram is a sentence that contains all the letters in the alphabet https://en.wikipedia.org/wiki/Pangram\n */\n\n/**\n * @function checkPangramRegex\n * @description - This function check pangram with the help of regex pattern\n * @param {string} string\n * @returns {boolean}\n * @example - checkPangramRegex(\"'The quick brown fox jumps over the lazy dog' is a pangram\") => true\n * @example - checkPangramRegex('\"Waltz, bad nymph, for quick jigs vex.\" is a pangram') => true\n */\nconst checkPangramRegex = (string) => {\n  if (typeof string !== 'string') {\n    throw new TypeError('The given value is not a string')\n  }\n\n  /**\n   * Match all 26 alphabets using regex, with the help of:\n   * Capturing group - () -> Groups multiple tokens together and creates a capture group for extracting a substring or using a backreference.\n   * Character set - [a-z] -> Matches a char in the range a to z in case-insensitive for the 'i' flag\n   * Negative lookahead - (?!) -> Specifies a group that can not match after the main expression (if it matches, the result is discarded).\n   * Dot - . -> Matches any character except linebreaks. Equivalent to\n   * Star - * -> Matches 0 or more of the preceding token.\n   * Numeric reference - \\{$n} -> Matches the results of a capture group. E.g. - \\1  matches the results of the first capture group & \\3 matches the third.\n   */\n  return string.match(/([a-z])(?!.*\\1)/gi).length === 26\n}\n\n/**\n * @function checkPangramSet\n * @description - This function detect the pangram sentence by HashSet\n * @param {string} string","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/TheAlgorithms/JavaScript/blob/5c39e87a9a31f279c60f830ad74a845e4788a517/String/CheckPangram.js#L1-L34","documentation":"Thrown as a TypeError by checkPangramRegex() when the input is not a string. The function runs string.match(/([a-z])(?!.*\\1)/gi) and reads .length, so a non-string receiver would fail or coerce misleadingly. Note: even for valid strings, if the string contains no letters at all, match() returns null and .length throws a separate TypeError — the input guard does not protect against that.","triggerScenarios":"Calling checkPangramRegex(null), checkPangramRegex(undefined), checkPangramRegex(123), or checkPangramRegex(['a','b']). Separately, checkPangramRegex('123!@#') passes the guard but throws on null.match().length downstream.","commonSituations":"Sentence fields that are sometimes null; numeric-only input mistaken for text; stripped strings that lost all alphabetic content.","solutions":["Coerce: checkPangramRegex(String(s)).","For the null-match risk, ensure the string contains at least one letter before calling, or wrap in try/catch.","Prefer checkPangramSet (error 139) for strings that may have no letters, since it uses a Set and does not dereference null."],"exampleFix":"// before\ncheckPangramRegex(sentence)\n\n// after\nconst s = String(sentence ?? '')\nconst isPangram = /[a-z]/i.test(s) ? checkPangramRegex(s) : false","handlingStrategy":"type-guard","validationCode":"function safeCheckPangramRegex(s) {\n  if (typeof s !== 'string') {\n    throw new TypeError('Expected a string')\n  }\n  if (!/[a-z]/i.test(s)) return false // avoid null match downstream\n  return checkPangramRegex(s)\n}","typeGuard":"function isStringWithLetters(v) {\n  return typeof v === 'string' && /[a-z]/i.test(v)\n}","tryCatchPattern":"try {\n  checkPangramRegex(sentence)\n} catch (e) {\n  if (e instanceof TypeError) {\n    return false\n  }\n  throw e\n}","preventionTips":["Coerce input with String() before calling.","Ensure the string contains at least one letter to avoid the null-match TypeError on .length.","Prefer checkPangramSet for inputs that may lack letters."],"tags":["type-check","string","pangram","regex","input-validation"],"backgroundTag":null,"analyzedSha":"5c39e87a9a31f279c60f830ad74a845e4788a517","analyzedAt":"2026-08-13T04:54:54.474Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}