Published on January 26, 2024By DeveloperBreeze

// Immediately Invoked Function Expression (IIFE) to detect the browser and version
const browser = (function() {
    // Get user agent string from navigator
    const userAgent = navigator.userAgent;

    // Regular expression to match browser name and version
    const match = userAgent.match(/(chrome|firefox|safari|opera|edge|msie)\/(\d+(\.\d+)?)/i);

    // Return the detected browser information or 'Unknown' if not matched
    return match ? { name: match[1], version: match[2] } : 'Unknown';
})();

// Logging the detected browser information
console.log('Browser:', browser);

Comments

Please log in to leave a comment.

Continue Reading:

Generate Random Password

Published on January 26, 2024

javascriptpythonphp

JavaScript Validate URL

Published on January 26, 2024

javascript

Detect Dark Mode Preference

Published on January 26, 2024

javascript

Calculate Greatest Common Divisor (GCD) of Two Numbers

Published on January 26, 2024

javascript

Calculate Distance Between Two Points

Published on January 26, 2024

javascript

Convert Array of Objects to CSV

Published on January 26, 2024

javascript

Validate Password Strength

Published on January 26, 2024

javascript

Parse JSON String to Object

Published on January 26, 2024

javascript

Validating Credit Card Numbers in JavaScript

Published on January 26, 2024

javascript