bhylu.com

Advertisements

JS Errors Silent

Some mistakes produce a wrong value without throwing. Use an explicit check when missing data is not acceptable.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

const session = {};
if (!Object.hasOwn(session, "places")) {
  console.log("The place count is missing.");
}

What happens

The missing field is reported instead of being used in a calculation.