if (!user || typeof user.nam !== 'string') {
throw new Error("Missing or invalid 'nam' on user");
}
Contemporary JavaScript has optional chaining, default values, and reflective tools like Object.hasOwn, which are all web standards. You just have to know how to use them.