---
title: "How to detect my browser version using JavaScript?"  
description: "How to detect my browser version using JavaScript?"  
author: "Utpal Vishwas"  
published: 2023-07-13  
updated: 2023-07-14  
canonical: https://www.mindstick.com/forum/159070/how-to-detect-my-browser-version-using-javascript  
category: "javascript"  
tags: ["javascript"]  
reading_time: 2 minutes  

---

# How to detect my browser version using JavaScript?

How to [detect](https://www.mindstick.com/forum/1906/detect-when-cd-drive-was-closed) my [browser](https://www.mindstick.com/blog/155254/which-is-the-best-internet-browser) [version](https://www.mindstick.com/articles/12845/things-to-remember-while-migrating-odoo-to-a-better-version) using [JavaScript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript)?

## Replies

### Reply by Aryan Kumar

Sure, here is how to detect your browser version using JavaScript:

JavaScript

```plaintext
// Get the user agent string.
const userAgent = navigator.userAgent;

// Extract the browser version.
const browserVersion = userAgent.match(/(Chrome|Firefox|Edge|Safari|Opera|IE)\/(\d+\.\d+)/);

// If the browser version is not found, return undefined.
if (!browserVersion) {
    return undefined;
}

// Return the browser version.
return browserVersion[2];
```

This code will first get the user agent string from the `navigator` object. The user agent string is a string that identifies the browser and operating system that the user is using.

Next, the code will use the `match()` method to extract the browser version from the user agent string. The `match()` method takes a regular expression as an argument and returns an array of matches if the regular expression matches the string.

The regular expression in this code matches the following strings:

- `Chrome/<version>`
- `Firefox/<version>`
- `Edge/<version>`
- `Safari/<version>`
- `Opera/<version>`
- `IE/<version>`

If the regular expression does not match the user agent string, the `match()` method will return an empty array.

Finally, the code will return the browser version if it was found. If the browser version was not found, the code will return `undefined`.

Here is an example of how to use this code:

JavaScript

```plaintext
const browserVersion = detectBrowserVersion();

if (browserVersion) {
    console.log(`You are using Chrome version ${browserVersion}`);
} else {
    console.log(`Your browser version could not be detected.`);
}
```

This code will first call the `detectBrowserVersion()` function to get the browser version. If the browser version is found, the code will log the browser version to the console. If the browser version is not found, the code will log a message to the console.


---

Original Source: https://www.mindstick.com/forum/159070/how-to-detect-my-browser-version-using-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
