Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Front End Technology Articles
Page 330 of 652
How do I clear the usage of setInterval()?
The setInterval() method executes a function repeatedly at specified intervals. Unlike setTimeout() which runs once, setInterval() continues indefinitely until cleared. Syntax let intervalId = setInterval(function, delay); Example: Basic setInterval Usage let count = 0; let intervalId = setInterval(function() { count++; console.log("Hello " + count); // Stop after 3 executions if (count === 3) { clearInterval(intervalId); ...
Read MoreHow to set whether the style of the font is normal, italic or oblique with JavaScript?
To set the style of the font in JavaScript, use the fontStyle property. This property accepts three values: normal, italic, and oblique. Syntax element.style.fontStyle = "normal" | "italic" | "oblique"; Example: Setting Font Style to Italic This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This ...
Read MoreHow to workaround Objects vs arrays in JavaScript for key/value pairs?
When you need key-value pairs in JavaScript, objects are the preferred choice over arrays. Objects provide direct key-based lookup, making data retrieval more efficient than searching through array indices. Why Objects Over Arrays for Key-Value Pairs Arrays use numeric indices and are optimized for ordered data, while objects are designed for key-value associations. Using objects allows you to access values directly by their keys. Basic Object Syntax Store key-value pairs using object literal syntax: var players = { 600: 'Sachin', 300: 'Brad' }; console.log(players[600]); // ...
Read MoreWhy is [1,2] + [3,4] = "1,23,4" in JavaScript?
The JavaScript's + operator is used to add two numbers or join two strings. However, when used with arrays, it doesn't concatenate them as you might expect. Instead, it converts both arrays to strings and then concatenates those strings. What Happens with [1, 2] + [3, 4] When JavaScript encounters the + operator between two arrays, it follows these steps: Convert each array to a string using the toString() method Concatenate the resulting strings // Step 1: Arrays are converted to strings console.log([1, 2].toString()); // "1, 2" console.log([3, 4].toString()); // "3, ...
Read MoreIs it correct to use JavaScript Array.sort() method for shuffling?
No, it is not correct to use JavaScript's Array.sort() method for shuffling arrays. While it may appear to work, it produces biased results and is not a proper shuffling algorithm. Why Array.sort() Fails for Shuffling Using Array.sort(() => Math.random() - 0.5) seems like a clever shortcut, but it doesn't produce truly random shuffles. The sort algorithm expects consistent comparison results, but random comparisons violate this assumption. // WRONG: Biased shuffling with sort() let arr = [1, 2, 3, 4, 5]; let biasedShuffle = arr.sort(() => Math.random() - 0.5); console.log("Biased result:", biasedShuffle); Biased result: ...
Read MoreIs their a negative lookbehind equivalent in JavaScript?
JavaScript supports negative lookbehind assertions in modern environments (ES2018+), but older browsers require workarounds using character classes and capturing groups. Modern Negative Lookbehind (ES2018+) ES2018 introduced native negative lookbehind syntax (?: let text = 'He said "hello" and she said "goodbye"'; let result = text.replace(/(? breaks down as: (^|[^\]) — Captures either start of string OR any character except backslash " — Matches the quote to replace $1' — Replaces with the captured character plus single quote Browser Compatibility Comparison Method Browser Support Performance Native (? Chrome ...
Read MoreWebGL: Prevent color buffer from being cleared in HTML5
In WebGL, the color buffer is automatically cleared at the beginning of each frame by default. This can be problematic when you want to preserve previous drawings for effects like trails or persistent graphics. The Problem Even when you manually clear the color buffer using clearColor() and clear(), the WebGL context automatically clears the drawing buffer before the next frame: // Manual clearing - but buffer still gets cleared automatically gl.clearColor(0.0, 0.0, 0.0, 1.0); gl.clear(gl.COLOR_BUFFER_BIT); This automatic clearing happens at the beginning of the next draw cycle, making it impossible to build up graphics ...
Read MoreIs there a way to print all methods of an object in JavaScript?
In JavaScript, methods are object properties that contain functions. Sometimes you need to inspect an object to discover all its available methods. This tutorial shows how to print all methods of an object using different approaches. A method is simply a function stored as an object property. When you call obj.methodName(), you're executing the function stored in that property. JavaScript provides several ways to discover these function properties. Using Object.getOwnPropertyNames() Method The Object.getOwnPropertyNames() method returns an array of all properties (including non-enumerable ones) found directly on an object. We can filter this array to find only function ...
Read MoreHow to set named cookies in JavaScript?
To set named cookies in JavaScript, use document.cookie with the format name=value. Named cookies allow you to store multiple key-value pairs that can be retrieved later. Basic Syntax document.cookie = "cookieName=cookieValue; expires=date; path=/"; Example: Setting a Customer Name Cookie function WriteCookie() { if (document.myform.customer.value == "") { alert("Enter some ...
Read MoreHow to design a custom alert box using JavaScript?
In this tutorial, we are going to create one custom alert box using JavaScript. The alert box signifies a box that appears with some message on it whenever you click a button and if we add some styling to the box and mould it according to our requirements then it will be a custom alert box. Approach to Design Custom Alert Box To create a custom alert box, we will use a jQuery library which is used to simplify the HTML DOM manipulation and it also provides us with better use of event handling and CSS animation with ...
Read More