language
Preferred browser language.
navigator exposes information about the browser, device capabilities and connection context.
console.log(navigator.language); console.log(navigator.onLine); console.log(navigator.userAgent);
Browser APIs & BOM
navigator contains browser and device information such as language, online status and supported APIs.
Some navigator values are privacy-sensitive, reduced or unreliable. Feature detection is usually better than user-agent detection.
When you use navigator data, treat it as a hint, not as a perfect identity for the user or device.
Preferred browser language.
Browser online/offline hint.
Legacy browser identification string.
APIs such as clipboard, geolocation and serviceWorker are exposed through navigator.
Examples
if ("clipboard" in navigator) {
enableCopyButton();
} else {
showManualCopyFallback();
}
if (navigator.userAgent.includes("Chrome")) {
enableFeature();
}
Code patterns
These examples focus on practical browser APIs: URL state, storage, cookies, clipboard, permissions, observers and offline-capable platform tools.
Useful for formatting defaults.
const locale = navigator.language;
Check and listen for changes.
console.log(navigator.onLine);
window.addEventListener("online", updateStatus);
window.addEventListener("offline", updateStatus);
Check whether an API exists.
if ("clipboard" in navigator) {
console.log("Clipboard supported");
}
Prefer feature detection.
if ("serviceWorker" in navigator) {
registerWorker();
}
Rules that matter
Browser APIs are powerful because they touch privacy, navigation, storage, permissions and performance. Use them deliberately.
Ask whether the API exists.
A network can be present while the server is unreachable.
Do not collect navigator data without a reason.
It is brittle and often misleading.
Language affects formatting, not necessarily user identity.
Capabilities vary between browsers and contexts.
Production thinking
navigator helps adapt to capabilities without hard-coding browser assumptions.
Capability checks should lead to usable fallbacks, not disabled experiences.
Production browser-feature code should detect APIs, handle absence and avoid unnecessary fingerprinting.
Feature detection keeps client-side behavior reliable across crawlers and browsers.
Live code lab
The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.
Mini assignment
Practice assignment
Try it yourself
Self-check
If you can explain support, permissions, fallback and cleanup, you are ready to use the API responsibly.
Senior audit upgrade