{"success":true,"name":"javascript-typeof-lies-null-is-object-arrays-are-too-use-the","description":"Working in JavaScript and a type check passes for values it shouldn't","category":"ai-brimind","path":"ai-brimind/javascript-typeof-lies-null-is-object-arrays-are-too-use-the/SKILL.md","file":"SKILL.md","content":"---\nname: javascript-typeof-lies-null-is-object-arrays-are-too-use-the\ndescription: \"Working in JavaScript and a type check passes for values it shouldn't\"\n---\n\n# JavaScript typeof Lies: null Is 'object', Arrays Are Too — Use the Right Check for Each Question\n\n## When to use\nProject is JavaScript, and code uses typeof to distinguish objects, arrays, or missing values — or a 'this is an object' branch crashes on null.\n\n## Example request\ntypeof value === 'object' guards property access → null passes the guard and crashes inside; the famous null-is-object lie. same check meant to exclude arrays → arrays are 'object' too, the branch mishandles them; hidden array. typeof NaN → 'number', so 'is a number' admits the poison value; certified impostor. — each asked typeof a question it doesn't answer.\n\n## Instructions\nAct as a customs officer who knows some passports in this country are historically misprinted and checks the person, not just the stamp. JavaScript's typeof carries decades-old quirks that make it the wrong tool for common questions: typeof null is 'object' (a legacy bug now permanent), arrays and objects both report 'object', and NaN proudly reports 'number' — so match each question to its correct check instead: is it a real object? — check typeof is 'object' AND it isn't null, in that order; is it an array? — use the dedicated array check (Array.isArray), never typeof; is it a usable number? — combine the number type check with the NaN exclusion per the NaN rules; is it missing? — compare against null/undefined explicitly per the absence rules, since typeof only distinguishes undefined. Write these compound checks once as tiny named helpers ('isObject', 'isValidNumber') so the subtlety lives in one tested place instead of being re-derived — slightly wrong — at every call site. When a type-branch mishandles a value, print the value AND its typeof before theorizing; the lie is usually right there. Only proceed once every type check in the change asks its question with the tool that actually answers it — because typeof answers six questions, and juniors routinely ask it ten.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #818\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}