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
Javascript Articles
Page 370 of 534
Program to find largest of three numbers - JavaScript
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 MoreImprove performance of a HTML5 Canvas with particles bouncing around
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 MoreDifference between MessageChannel and WebSockets in HTML5
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 MoreConverting days into years months and weeks - JavaScript
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 MoreDoes 'position: absolute' conflict with flexbox?
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 MoreCheck Disarium number - JavaScript
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 MoreHTML5 / JS storage event handler
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 MoreCount total punctuations in a string - JavaScript
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 MoreAny ideas on how to prepare for the future of Flash/ Flex/ HTML5 Development?
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 MoreRemove all whitespaces from string - JavaScript
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