Example 1 — Feature Detect
Check whether the Network Information API is available.
if ("connection" in navigator && navigator.connection) {
console.log("connection supported");
} else {
console.log("connection missing — use defaults");
} How It Works
- Use
in. Safe check before reading fields. - Confirm the object. Some environments expose the key as empty.
- Fallback. If missing, keep a sensible default quality.
- No side effects. Detection alone does not change the network.

