Loading...
Loading...
TypeError: Cannot read properties of undefined (reading 'toLowerCase')This error happens when you try to call .toLowerCase() on a variable that is undefined or null. Since undefined is not an object or string, it has no methods, so JavaScript throws a TypeError.
The ?. operator will return undefined instead of throwing if the value is nullish.
const input = undefined;
// ❌ Crashes
const lower = input.toLowerCase();
// ✅ Safe
const lower = input?.toLowerCase();Use the nullish coalescing operator ?? to provide a default empty string.
const lower = (input ?? "").toLowerCase();Use our Data Sanitizer to clean and normalize text before processing it.