JavaScript Navigator

Beginner
8 min read
Updated: Nov 2026
3 examples
Browser info

Definition and Usage

The navigator object describes the browser and device environment. You read things like navigator.language, navigator.onLine, and (with care) navigator.userAgent.

Modern APIs hang off Navigator too: navigator.mediaDevices for camera/mic, navigator.clipboard for copy/paste, and share helpers such as canShare / share when supported.

This page teaches what Navigator is. Method and property guides live under this section.

userAgent is a poor feature test.

Prefer checking for the API you need ("mediaDevices" in navigator) instead of parsing the user-agent string.

JavaScript Syntax

Common Navigator reads:

JavaScript
console.log(navigator.language);
console.log(navigator.onLine);
console.log(typeof navigator.mediaDevices);
console.log(navigator.userAgent.length > 0);

Core Ideas

Ideas every Navigator tutorial builds on:

IdeaExampleRemember
languagenavigator.languagePreferred UI language
onLinenavigator.onLineNetwork connectivity hint
userAgentnavigator.userAgentAvoid for feature detection
mediaDevicesnavigator.mediaDevicesCamera and microphone
clipboardnavigator.clipboardAsync clipboard API
sharenavigator.share?.()Web Share when available

JavaScript Examples

Three short programs that show how Navigator works.

Example 1 — Read the preferred language

language is a BCP 47 tag such as en-US.

JavaScript
console.log(typeof navigator.language);
console.log(navigator.language.length > 0);

How It Works

  1. language is always a string in supporting browsers.
  2. It reflects the userโ€™s preferred language.
  3. Use it to pick default locale formatting.

Example 2 — Check onLine

onLine is a boolean hint, not a perfect connectivity test.

JavaScript
console.log(typeof navigator.onLine);

How It Works

  1. onLine is true or false.
  2. It can be wrong on captive portals.
  3. Still useful for quick UI hints.

Example 3 — Detect mediaDevices

Feature-detect before calling getUserMedia.

JavaScript
console.log("mediaDevices" in navigator);

How It Works

  1. "mediaDevices" in navigator is a safe check.
  2. If true, you can call getUserMedia.
  3. Still handle permission errors with try/catch or .catch.

Next: Navigator Guides

Continue with methods such as canShare and the property pages.

Look upWhy
canShare()Test Web Share payloads
share()Open the system share sheet
languagePreferred language tag
onLineConnectivity hint

Full lists: canShare().

Frequently Asked Questions

navigator is a browser object that describes the environment: language, online status, user agent, and entry points such as mediaDevices and clipboard.
Usually no. Feature-detect APIs instead. userAgent strings are messy and often misleading.
It is a hint. true does not guarantee a working internet connection. Pair it with real request error handling.
navigator.mediaDevices.getUserMedia. See also the MediaStream hub for the stream object you get back.
Open canShare() and other Navigator methods, then MediaStream and Screen.

Open a Navigator method

Start with canShare(), then browse properties like language and onLine.

canShare() →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P ๐Ÿ”—

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful