Skip to main content

What does navigator do?

1. What navigator is

navigator is a property of the window object, and it represents the Browser Object Model (BOM) - an interface that lets JavaScript interact with the browser, not the page.

javascript
console.log(window.navigator === navigator); // true

2. Example:

javascript
console.log(navigator.userAgent); console.log(navigator.language); console.log(navigator.onLine);

Prints information like:

javascript
"Mozilla/5.0 (Windows NT 10.0; Win64; x64)..." "en-US" true

3. Main properties of navigator:

PropertyWhat it does
navigator.userAgenta string describing the browser and OS
navigator.languagethe user's interface language ("en-US", "uk-UA")
navigator.languagesan array of preferred languages
navigator.platformthe platform/OS ("Win32", "MacIntel", "Linux x86_64")
navigator.onLinetrue if there is internet access
navigator.cookieEnabledtrue if cookies are enabled in the browser
navigator.hardwareConcurrencythe number of logical CPU cores
navigator.deviceMemorythe device's RAM size (in GB)
navigator.vendorthe browser vendor (e.g. "Google Inc.")

4. navigator methods:

MethodDescription
navigator.geolocation.getCurrentPosition()get the user's geolocation
navigator.clipboard.writeText() / readText()work with the clipboard
navigator.share()trigger the system "Share" dialog (on mobile)
navigator.vibrate()vibrate on mobile devices
navigator.mediaDevices.getUserMedia()access the camera and microphone
navigator.serviceWorkerwork with Service Workers (PWA, offline mode)
navigator.permissions.query()check whether an API is allowed (e.g. geolocation)

5. Usage examples:

Check the browser:

javascript
if (navigator.userAgent.includes("Chrome")) { console.log("User is on Chrome"); }

Check the connection:

javascript
if (!navigator.onLine) { alert("No Internet connection!"); }

Get the current coordinates:

javascript
navigator.geolocation.getCurrentPosition(pos => { console.log(pos.coords.latitude, pos.coords.longitude); });

This method asks the user for permission.

Copy text to the clipboard:

javascript
navigator.clipboard.writeText("Hello, world!");

Get the user's language:

javascript
console.log(`Your language: ${navigator.language}`);

6. Structure:

javascript
window └── navigator ├── userAgent ├── language ├── geolocation ├── clipboard ├── mediaDevices └── ...

In short:

What it doesProvides information about the browser and device
Where it livesInside window (window.navigator)
What you can learnbrowser type, language, OS, online status
What you can doget geolocation, copy to clipboard, trigger share, use the camera
A typical examplenavigator.userAgent, navigator.onLine, navigator.geolocation.getCurrentPosition()

Summary: navigator is an object through which JavaScript can learn the browser's and device's characteristics and interact with system capabilities (geolocation, camera, clipboard, PWA, etc.).

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.