Explore Bato Web Agency Webflow Certified Partner Profile Explore Bato Web Agency Webflow Certified Partner Profile

TypeError: Cannot read properties of undefined (reading ‘toLowerCase’)

Illustration without a description Illustration without a description

The call to toLowerCase() reached an undefined value. Trace it back to the field that supplies the string. A differently named API key, an omitted form field or a query parameter that is absent can all leave the receiver undefined.

 

Inspect the raw value before trimming or changing case. If the email is required, reject anything that is not a string where the input enters the application. When the field is optional, decide how the application should represent its absence before invoking any string method.

 

A blanket String() conversion can turn missing data into the literal text undefined. That looks like a string to later checks even though the caller never supplied an email address.

 

function normalizedEmail(email) { if (typeof email !== 'string') throw new TypeError('email must be text'); return email.trim().toLowerCase(); }

 

Inspect the email field before normalization and try the same function with an omitted value and a valid address.