DeveloperBreeze

Detecting Browser and Version

// 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);

Continue Reading

Discover more amazing content handpicked just for you

Tutorial
javascript

Running JavaScript in the Browser Console

  • Write multi-line code directly in the console:
     function greet(name) {
       return `Hello, ${name}!`;
     }
     greet("Alice");

Dec 10, 2024
Read More
Tutorial
javascript

Mastering console.log Advanced Usages and Techniques

You can measure the time it takes for a block of code to execute using console.time and console.timeEnd. This is useful for performance testing.

console.time('loop');
for (let i = 0; i < 1000000; i++) {
  // Some operation
}
console.timeEnd('loop'); // Output: loop: <time in ms>

Sep 02, 2024
Read More
Code
javascript

Checking if the User is Accessing from a Mobile Device in JavaScript

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Validating Credit Card Numbers in JavaScript

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Parse JSON String to Object

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Validate Password Strength

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Convert Array of Objects to CSV

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Calculate Distance Between Two Points

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Calculate Greatest Common Divisor (GCD) of Two Numbers

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Detect Dark Mode Preference

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

JavaScript Validate URL

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript python +1

Generate Random Password

No preview available for this content.

Jan 26, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!