{"record":{"id":"1fe1a236e140f692","repo":"TheAlgorithms/JavaScript","slug":"argument-is-not-a-string-1fe1a2","errorCode":null,"errorMessage":"Argument is not a string.","messagePattern":"Argument is not a string\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"String/CheckCamelCase.js","lineNumber":13,"sourceCode":"// CheckCamelCase method checks the given string is in camelCase or not.\n\n// Problem Source & Explanation: https://en.wikipedia.org/wiki/Camel_case\n\n/**\n * checkCamelCase method returns true if the string in camelCase, 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 camelCase, else return false.\n */\nconst checkCamelCase = (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 { checkCamelCase }\n","sourceCodeStart":1,"sourceCodeEnd":21,"githubUrl":"https://github.com/TheAlgorithms/JavaScript/blob/5c39e87a9a31f279c60f830ad74a845e4788a517/String/CheckCamelCase.js#L1-L21","documentation":"Thrown as a TypeError by checkCamelCase() when varName is not a string. The function tests varName against the regex /^[a-z][A-Za-z]*$/ via RegExp.prototype.test, which coerces non-strings but the library chooses to reject them explicitly to avoid surprising truthy results (e.g. numbers coercing to strings).","triggerScenarios":"Calling checkCamelCase(null), checkCamelCase(undefined), checkCamelCase(123), checkCamelCase(['myVar']), or checkCamelCase({name: 'myVar'}).","commonSituations":"Validating identifiers sourced from JSON where the field is absent; AST node names that may be numbers; form input not yet coerced.","solutions":["Coerce: checkCamelCase(String(name)).","Guard: if (typeof name === 'string') checkCamelCase(name).","Default the parameter at the call site: checkCamelCase(name ?? '')."],"exampleFix":"// before\nconst ok = checkCamelCase(node.name) // node.name may be undefined\n\n// after\nconst ok = typeof node.name === 'string' && checkCamelCase(node.name)","handlingStrategy":"type-guard","validationCode":"function safeCheckCamelCase(name) {\n  if (typeof name !== 'string') {\n    throw new TypeError('Expected a string')\n  }\n  return checkCamelCase(name)\n}","typeGuard":"function isString(v) {\n  return typeof v === 'string'\n}","tryCatchPattern":"try {\n  checkCamelCase(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 validation.","Default missing fields to empty string.","Guard with typeof at the 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"}