Front End Technology Articles

Page 361 of 652

How to fix Array indexOf() in JavaScript for Internet Explorer browsers?

Ramu Prasad
Ramu Prasad
Updated on 15-Mar-2026 513 Views

Internet Explorer versions 8 and below don't support the Array.indexOf() method. This article shows how to fix this compatibility issue using polyfills and jQuery alternatives. The Problem In modern browsers, indexOf() returns the first index of an element in an array, or -1 if not found. However, IE8 and earlier throw an error when you try to use this method. Method 1: Using Array Polyfill Add this polyfill to support indexOf() in older IE browsers: Method 2: Using jQuery.inArray() jQuery provides a cross-browser alternative with jQuery.inArray(): // Syntax: ...

Read More

How to convert the image into a base64 string using JavaScript?

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 676 Views

To convert an image into a base64 string using JavaScript, you can use the FileReader API for local files or combine XMLHttpRequest with FileReader for remote images. Base64 encoding represents binary image data as a text string, making it useful for embedding images directly in HTML or CSS. Method 1: Converting Local Image Files For user-uploaded files, use the FileReader API with an input element: document.getElementById('imageInput').addEventListener('change', function(e) { ...

Read More

How to understand JavaScript module pattern?

Lokesh Badavath
Lokesh Badavath
Updated on 15-Mar-2026 347 Views

The JavaScript Module Pattern is a design pattern that encapsulates private and public methods and variables within a single object. It provides a way to create modular, maintainable code while avoiding global namespace pollution. What is the Module Pattern? The Module pattern uses Immediately Invoked Function Expressions (IIFE) to create a closure that contains private variables and functions. It returns an object with public methods that can access these private elements. Why Use the Module Pattern? Maintainability − Modules are self-contained and reduce dependencies, making code easier to maintain and improve independently. Namespace Protection − ...

Read More

How to get the body's content of an iframe in JavaScript?

Lokesh Badavath
Lokesh Badavath
Updated on 15-Mar-2026 24K+ Views

To get the body's content of an iframe in JavaScript, you need to access the iframe element first, then navigate to its document and retrieve the body content. This requires the iframe to be from the same origin due to browser security policies. Basic Approach First, get the iframe element using document.getElementById(), then access its content through contentWindow.document or contentDocument: Get Iframe Content Get Iframe Content ...

Read More

What is JavaScript AES Encryption?

Lokesh Badavath
Lokesh Badavath
Updated on 15-Mar-2026 15K+ Views

AES (Advanced Encryption Standard) is a symmetric encryption algorithm that uses the same key to encrypt and decrypt data. In JavaScript, we can implement AES encryption using libraries like CryptoJS to secure sensitive information in web applications. What is AES Encryption? AES is a widely adopted encryption standard that provides strong security for data protection. It's called "symmetric" because the same key is used for both encryption and decryption processes. This algorithm is commonly used in messaging applications like WhatsApp and Signal to ensure secure communication. How AES Works The encryption process involves converting plain text ...

Read More

Is it safe to assume strict comparison in a JavaScript switch statement?

Priya Pallavi
Priya Pallavi
Updated on 15-Mar-2026 222 Views

JavaScript switch statements use strict comparison (===) to match cases, not loose comparison (==). This means both value and type must match exactly. Understanding Switch Comparison Let's test this with a simple example to see which case matches: switch(1) { case '1': alert('Switch comparison: Not Strict.'); break; case 1: alert('Switch comparison: Strict.'); break; default: alert('Default'); } ...

Read More

How to disable browser's back button with JavaScript?

George John
George John
Updated on 15-Mar-2026 3K+ Views

To disable the browser's back button, you can use JavaScript's history.forward() method to prevent users from navigating backward. This technique forces the browser to stay on the current page when the back button is clicked. Basic Approach The core idea is to push the current page forward in history whenever the user tries to go back: Disable Browser Back Button Main Page Next Page ...

Read More

How to perform Automated Unit Testing with JavaScript?

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 283 Views

To perform automated unit testing in JavaScript, Unit.js is a cross-platform open-source unit testing framework that provides a simple and intuitive API for testing JavaScript applications. What is Unit.js? Unit.js is a JavaScript testing framework that works in both Node.js and browsers. It offers a fluent interface for writing readable test assertions and supports various testing patterns. Basic Syntax Unit.js uses a chainable syntax where you specify the data type and then chain assertion methods: test.dataType(value).assertionMethod(expectedValue); Simple String Testing Example Here's a basic example of testing a string value: ...

Read More

In JavaScript inheritance how to differentiate Object.create vs new?

Abhinanda Shri
Abhinanda Shri
Updated on 15-Mar-2026 229 Views

In JavaScript inheritance, Object.create() and new serve different purposes when setting up prototype chains. Understanding their differences is crucial for proper inheritance implementation. Object.create() - Prototype Only Inheritance When using Object.create(), you inherit only the prototype methods without executing the parent constructor: function BaseClass(name) { this.name = name; console.log("BaseClass constructor called"); } BaseClass.prototype.greet = function() { return "Hello from " + this.name; }; function ChildClass(name) { this.name = name; } // Using Object.create - inherits prototype only ...

Read More

Is there a way to add/remove several classes in one single instruction with classList in HTML and JavaScript?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 272 Views

The classList property returns the class names of an element as a DOMTokenList object. While it's read-only, you can modify it using methods like add() and remove(). The classList property automatically prevents duplicate classes from being added. You can add or remove multiple classes in a single instruction using several approaches. Using Multiple Parameters (ES6+) Modern browsers support passing multiple class names as separate parameters: Content const element = document.getElementById('myDiv'); // Add multiple classes element.classList.add('active', 'highlighted', 'primary'); console.log(element.className); // Remove multiple classes element.classList.remove('active', 'highlighted'); console.log(element.className); container active ...

Read More
Showing 3601–3610 of 6,519 articles
« Prev 1 359 360 361 362 363 652 Next »
Advertisements