{"record":{"id":"ca476222f41b5c2e","repo":"TheAlgorithms/JavaScript","slug":"argument-is-not-a-string-ca4762","errorCode":null,"errorMessage":"Argument is not a string.","messagePattern":"Argument is not a string\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"String/CheckPascalCase.js","lineNumber":13,"sourceCode":"// CheckPascalCase method checks the given string is in PascalCase or not.\n\n// Problem Source & Explanation: https://www.theserverside.com/definition/Pascal-case\n\n/**\n * CheckPascalCase method returns true if the string in PascalCase, else return the false.\n * @param {String} VarName the name of the variable to check.\n * @returns `Boolean` return true if the string is in PascalCase, else return false.\n */\nconst CheckPascalCase = (VarName) => {\n  // firstly, check that input is a string or not.\n  if (typeof VarName !== 'string') {\n    throw new TypeError('Argument is not a string.')\n  }\n\n  const pat = /^[A-Z][A-Za-z]*$/\n  return pat.test(VarName)\n}\n\nexport { CheckPascalCase }\n","sourceCodeStart":1,"sourceCodeEnd":21,"githubUrl":"https://github.com/TheAlgorithms/JavaScript/blob/5c39e87a9a31f279c60f830ad74a845e4788a517/String/CheckPascalCase.js#L1-L21","documentation":"Pre-condition guard at the top of CheckPascalCase. The function tests a variable name against the regex /^[A-Z][A-Za-z]*$/ (an uppercase letter followed by zero or more letters). Before it can call regex.test(), it rejects any input whose typeof is not 'string' with TypeError. This is the library's standard pattern for protecting .test() from non-string arguments.","triggerScenarios":"Calling CheckPascalCase(undefined), CheckPascalCase(null), CheckPascalCase(42), CheckPascalCase({name:'Foo'}), or CheckPascalCase(['Foo']). Any value where typeof !== 'string'.","commonSituations":"Reading an optional field from JSON.parse where the key is missing (yields undefined); form/CLI input parsed as a number; a destructured object property that was renamed or absent; spreading an array element that is undefined.","solutions":["Pass only string values: coerce or validate the source before calling, e.g. ensure the value is a string via typeof.","Default the variable when it may be missing: const name = raw?.name ?? ''.","Wrap the call in try/catch when the input crosses a trust boundary (user input, external API payload)."],"exampleFix":"// before\nCheckPascalCase(maybeName)\n\n// after\nif (typeof maybeName === 'string') CheckPascalCase(maybeName)\n// or\nCheckPascalCase(typeof maybeName === 'string' ? maybeName : '')","handlingStrategy":"type-guard","validationCode":"if (typeof VarName !== 'string') {\n  throw new TypeError('VarName must be a string, got ' + typeof VarName)\n}\nCheckPascalCase(VarName)","typeGuard":"const isNonEmptyString = (v) => typeof v === 'string' && v.length > 0","tryCatchPattern":"try {\n  CheckPascalCase(name)\n} catch (e) {\n  if (e instanceof TypeError && /not a string/i.test(e.message)) {\n    // handle bad input type\n  } else throw e\n}","preventionTips":["Type all boundary inputs in JSDoc/@ts-check or TypeScript.","Coerce optional fields with ?? '' at the read site.","Never pass raw parsed-JSON fields without a typeof check."],"tags":["string","validation","type-guard","naming-convention"],"backgroundTag":null,"analyzedSha":"5c39e87a9a31f279c60f830ad74a845e4788a517","analyzedAt":"2026-08-13T04:54:54.474Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}