iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

JS Navigator

window.navigator describes the browser, OS, and a growing list of device capabilities. Useful pieces are the connection info, languages, and feature-detection helpers.

Practical properties

PropertyWhat it returns
navigator.languagePreferred language tag, e.g. "en-US".
navigator.languagesOrdered list of preferred languages.
navigator.onLineBoolean — false means definitely offline.
navigator.cookieEnabledAre cookies enabled?
navigator.userAgentUA string — historically unreliable. Use feature detection instead.
navigator.userAgentDataModern UA Client Hints (Chromium).
navigator.hardwareConcurrencyLogical CPU cores.
navigator.deviceMemoryApproximate RAM in GB.

Useful sub-APIs

APIPurpose
navigator.clipboardRead / write the clipboard.
navigator.geolocationGet the user's coordinates (with consent).
navigator.serviceWorkerRegister service workers (PWA, offline).
navigator.mediaDevicesCamera, mic, screen-share.
navigator.share({ url, title })Native share sheet (mostly mobile).
navigator.connectionNetwork speed/type (Chromium).

Online/offline events

JS
window.addEventListener("online",  () => statusBar.textContent = "✓ online");
window.addEventListener("offline", () => statusBar.textContent = "⚠ offline");
Note: navigator.onLine only knows about the OS network state — it can't tell whether your specific server is reachable. Confirm with a fetch.
Tip: Don't parse the UA string to make UI decisions. Use feature detection ("clipboard" in navigator, typeof IntersectionObserver !== "undefined") — it survives browser changes.

Example

Example
<!DOCTYPE html>
<html>
<body>

<p id="out"></p>

<script>
document.getElementById("out").textContent = "Hello from JS Navigator!";
</script>

</body>
</html>
Try it Yourself »

Exercise

Show the user's preferred language tag.

console.log(navigator. );

Test yourself

Q1. Reliable feature detection beats…
Q2. `navigator.onLine` knows about…
Q3. User's preferred language is on…

Discussion

Loading…