{"record":{"id":"ccf5312e303ce797","repo":"TheAlgorithms/JavaScript","slug":"argument-is-not-a-string-ccf531","errorCode":null,"errorMessage":"Argument is not a string.","messagePattern":"Argument is not a string\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"String/CheckFlatCase.js","lineNumber":15,"sourceCode":"// checkFlatCase method checks if the given string is in flatcase or not. Flatcase is a convention\n// where all letters are in lowercase, and there are no spaces between words.\n// thisvariable is an example of flatcase. In camelCase it would be thisVariable, snake_case this_variable and so on.\n\n// Problem Source & Explanation: https://en.wikipedia.org/wiki/Naming_convention_(programming)\n\n/**\n * checkFlatCase method returns true if the string in flatcase, 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 flatcase, else return false.\n */\nconst checkFlatCase = (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]*$/\n  return pat.test(varname)\n}\n\nexport { checkFlatCase }\n","sourceCodeStart":1,"sourceCodeEnd":23,"githubUrl":"https://github.com/TheAlgorithms/JavaScript/blob/5c39e87a9a31f279c60f830ad74a845e4788a517/String/CheckFlatCase.js#L1-L23","documentation":"Thrown as a TypeError by checkFlatCase() when varname is not a string. The function tests varname against /^[a-z]*$/ via regex; the explicit guard rejects non-strings before coercion could mask bugs. Flatcase means all-lowercase with no separators (e.g. 'thisvariable').","triggerScenarios":"Calling checkFlatCase(null), checkFlatCase(undefined), checkFlatCase(123), or checkFlatCase(['name']).","commonSituations":"Identifier validation on data that may be missing; numeric or symbol identifiers from generated code.","solutions":["Coerce: checkFlatCase(String(name)).","Type-guard: if (typeof name === 'string').","Default missing values to empty string."],"exampleFix":"// before\ncheckFlatCase(identifier)\n\n// after\ncheckFlatCase(String(identifier ?? ''))","handlingStrategy":"type-guard","validationCode":"function safeCheckFlatCase(name) {\n  if (typeof name !== 'string') {\n    throw new TypeError('Expected a string')\n  }\n  return checkFlatCase(name)\n}","typeGuard":"function isString(v) {\n  return typeof v === 'string'\n}","tryCatchPattern":"try {\n  checkFlatCase(name)\n} catch (e) {\n  if (e instanceof TypeError && e.message === 'Argument is not a string.') {\n    return false\n  }\n  throw e\n}","preventionTips":["Coerce identifiers with String() before checking.","Default absent fields to empty string.","Type-guard at the validation boundary."],"tags":["type-check","string","naming-convention","input-validation"],"backgroundTag":null,"analyzedSha":"5c39e87a9a31f279c60f830ad74a845e4788a517","analyzedAt":"2026-08-13T04:54:54.474Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}