Javascript Articles

Page 370 of 534

Program to find largest of three numbers - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 618 Views

We are required to write a JavaScript function that takes in three or more numbers and returns the largest of those numbers. For example: If the input numbers are āˆ’ 4, 6, 7, 2, 3 Then the output should be āˆ’ 7 Method 1: Using Math.max() with Spread Operator The simplest approach is using the built-in Math.max() function with the spread operator: const findLargest = (...nums) => { return Math.max(...nums); }; console.log(findLargest(4, 6, 7, 2, 3)); console.log(findLargest(15, 8, 23, 1)); ...

Read More

Improve performance of a HTML5 Canvas with particles bouncing around

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 249 Views

To enhance the performance of HTML5 Canvas with particles bouncing around, several optimization techniques can dramatically improve frame rates and reduce CPU usage. Key Performance Optimization Techniques Separate the calculations from the drawing operations Request a redraw only after updating calculations Optimize collision detection by avoiding O(n²) comparisons Reduce callback usage and function calls Use inline calculations where possible Implement object pooling for particles Example: Optimized Particle System ...

Read More

Difference between MessageChannel and WebSockets in HTML5

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 233 Views

WebSockets and MessageChannel are both HTML5 communication technologies, but they serve different purposes. WebSockets enable real-time communication between browser and server, while MessageChannel facilitates secure communication between different browsing contexts within the same application. WebSockets Overview WebSockets provide bidirectional communication between browser and server over a single persistent connection. They're ideal for real-time applications like chat systems, live updates, and gaming. // WebSocket connection to server const socket = new WebSocket('wss://example.com/socket'); socket.onopen = function(event) { console.log('WebSocket connected'); socket.send('Hello Server!'); }; socket.onmessage = function(event) { ...

Read More

Converting days into years months and weeks - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 3K+ Views

We are required to write a JavaScript function that takes in a number (representing the number of days) and returns an object with four properties: years, months, weeks, days The properties should have proper values that can be made from the total number of days. We assume a standard year has 365 days and each month has 30 days for simplicity. Problem Example If the input is 738 days, the output should be: { years: 2, months: 0, weeks: 1, days: 1 } ...

Read More

Does 'position: absolute' conflict with flexbox?

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 343 Views

The position: absolute property can work with flexbox, but understanding their interaction is crucial for proper layout control. How Absolute Positioning Affects Flexbox When you apply position: absolute to a flex container, it removes the container from the normal document flow but maintains its flexbox properties for arranging child elements. Basic Example Here's how to combine absolute positioning with flexbox: .parent { display: flex; ...

Read More

Check Disarium number - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 442 Views

A Disarium number is a number where the sum of its digits raised to their respective positions equals the original number. Definition For a number with digits xy...z, it's a Disarium number if: xy...z = x^1 + y^2 + ... + z^n Where n is the total number of digits in the number. Example Let's check if 175 is a Disarium number: 175 = 1^1 + 7^2 + 5^3 = 1 + 49 + 125 = 175 Since the sum equals the original number, 175 is a Disarium ...

Read More

HTML5 / JS storage event handler

Jennifer Nicholas
Jennifer Nicholas
Updated on 15-Mar-2026 371 Views

Storage event handlers in HTML5 only fire when storage changes are triggered by another window or tab. This means storage events won't fire in the same window that made the change. Syntax window.addEventListener('storage', function(event) { // Handle storage changes from other windows }, false); Example: Basic Storage Event Handler Storage Event Example Storage Event Demo Open this page in another tab and click the button to see the event fire. ...

Read More

Count total punctuations in a string - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 750 Views

In JavaScript, you can count punctuation marks in a string by checking each character against a set of punctuation symbols. Common punctuation marks include periods, commas, semicolons, exclamation marks, question marks, and quotation marks. Common Punctuation Characters '!', ", ", "'", ";", '"', ".", "-", "?" Example Here's a JavaScript function that counts punctuation marks in a string: const str = "This, is a-sentence;.Is this a sentence?"; const countPunctuation = str => { const punct = "!, ';".?-"; let count = 0; ...

Read More

Any ideas on how to prepare for the future of Flash/ Flex/ HTML5 Development?

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 15-Mar-2026 150 Views

The web development landscape has evolved significantly since Flash's decline. Understanding the transition from Flash/Flex to modern HTML5 technologies is crucial for developers preparing for the future. The End of Flash Era Adobe Flash officially ended support in December 2020. Major browsers now block Flash content by default, and users must manually enable it for legacy applications. This marked the definitive shift toward modern web standards. HTML5: The Modern Web Standard HTML5 represents a collaboration between the World Wide Web Consortium (W3C) and the Web Hypertext Application Technology Working Group (WHATWG). It provides native support for ...

Read More

Remove all whitespaces from string - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 311 Views

We are required to write a JavaScript function that takes in a string and returns a new string with all the characters of the original string but with whitespaces removed. Method 1: Using a For Loop This approach iterates through each character and builds a new string excluding spaces: const str = "This is an example string from which all whitespaces will be removed"; const removeWhitespaces = str => { let newStr = ''; for(let i = 0; i < str.length; i++){ ...

Read More
Showing 3691–3700 of 5,340 articles
« Prev 1 368 369 370 371 372 534 Next »
Advertisements