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
Articles on Trending Technologies
Technical articles with clear explanations and examples
Converting seconds in years days hours and minutes in JavaScript
In this article, we create a function that takes in a number(num) which represents the number of seconds. So, it construct and return a string that contains information of years, days, hours and minutes contained in those seconds. Converting seconds into years, days, hours, and minutes in JavaScript involves breaking down a given total of seconds into more understandable time units. This process helps display elapsed time in a readable format. For the purpose of the article, we will consider that all the years have 365 days. Let us understand through some sample example of I/O Scenario ...
Read MoreWhat are the Pros and Cons of JavaScript Frameworks?
JavaScript has revolutionized web development over the past 25 years, with JavaScript frameworks becoming essential tools for modern developers. These frameworks provide structured approaches to building applications, offering both significant advantages and notable challenges. In this article, we'll explore what JavaScript frameworks are, their common use cases, and analyze the pros and cons of popular frameworks to help you make informed decisions for your projects. What are JavaScript Frameworks? JavaScript frameworks are pre-written code libraries that provide a foundation for building JavaScript applications. They offer developers a structured approach to development by providing: ...
Read MoreHow to add an object to a canvas using FabricJS?
In this article, we are going to learn how to add an object to the canvas by using the add method. After creating our canvas, we can populate it with various objects available in FabricJS like fabric.Circle, fabric.Ellipse or fabric.Line, etc. Syntax canvas.add(object: fabric.Object); Parameters object − This parameter is of type fabric.Object and holds the objects that we want to add to our canvas. Example 1: Creating Object Instance Inside canvas.add() Instead of creating the instance of an object first and then rendering it on the canvas by using ...
Read MoreHow is JavaScript less scoped than Java?
JavaScript has different scoping rules compared to Java, making it "less scoped" in terms of variable visibility and accessibility. Understanding these differences is crucial for developers working with both languages. What is Scope? Scope determines where variables can be accessed in your code. Java has strict block-level scoping, while JavaScript traditionally had function-level scoping (though modern JavaScript now supports block scoping with let and const). Java's Block-Level Scoping In Java, variables declared inside any block (curly braces) are only accessible within that block: // Java example public class ScopeExample { ...
Read MoreHow to check if the input date is equal to today's date or not using JavaScript?
We learn to check if the input date is equal to today's date or not using JavaScript in this tutorial. Sometimes, we need to take the date from users in the input field in various formats and check if input date and today's date match. Here, we will learn two approaches to check the equality of the input date with today's date. Method 1: Comparing Year, Month, and Date Separately Users can get the full year, month, and date from the timestamp of the Date object using various methods such as getFullYear(), getMonth(), and getDate(). Also, we ...
Read MoreDisplay the result difference while using ceil() in JavaScript?
The Math.ceil() function rounds a number UP to the nearest integer. While division might give decimal results, Math.ceil() ensures you get the next whole number. How Math.ceil() Works If your value is 4.5, 4.3, or even 4.1, Math.ceil() will return 5. It always rounds UP, unlike regular rounding. Example: Division Without ceil() Let's see normal division first: var result1 = 98; var result2 = 5; console.log("The actual result is=" + result1 / result2); The actual result is=19.6 Example: Division With ceil() Now let's apply Math.ceil() to round ...
Read MoreAlternate casing a string in JavaScript
We are required to write a JavaScript function that takes in a string and constructs a new string with all the uppercase characters from the original string converted to lowercase and all the lowercase characters converted to uppercase from the original string. For example: If the string is − const str = 'The Case OF tHis StrinG Will Be FLiPped'; Expected Output Then the output should be − const output = 'tHE cASE of ThIS sTRINg wILL bE flIpPED'; Using Manual Character Code Manipulation This approach manually checks character ...
Read MoreTransforming array to object JavaScript
Suppose we have an array of strings like this − const arr = [ 'type=A', 'day=45' ]; We are required to write a JavaScript function that takes in one such array. The function should construct an object based on this array. The object should contain a key/value pair for each string in the array. For any string, the part before '=' becomes the key and the part after it becomes the value. Method 1: Using for Loop const arr = [ 'type=A', 'day=45' ]; const arrayToObject = (arr = []) => ...
Read MoreDash separated cartesian product of any number of arrays in JavaScript
We need to write a JavaScript function that takes any number of arrays and computes their cartesian product, with elements separated by dashes. The cartesian product combines every element from the first array with every element from the second array, and so on. What is Cartesian Product? The cartesian product of two or more sets is the set of all possible combinations where we pick one element from each set. For example, if we have arrays ['a', 'b'] and ['1', '2'], the cartesian product would be ['a-1', 'a-2', 'b-1', 'b-2']. Implementation Here's how we can implement ...
Read MoreFinding sum of sequence upto a specified accuracy using JavaScript
We need to find the sum of a sequence where each term is the reciprocal of factorials. The sequence is: 1/1, 1/2, 1/6, 1/24, ... where the nth term is 1/n!. Understanding the Sequence The sequence can be written as: 1st term: 1/1! = 1/1 = 1 2nd term: 1/2! = 1/2 = 0.5 3rd term: 1/3! = 1/6 ≈ 0.167 4th term: 1/4! = 1/24 ≈ 0.042 Each term is 1 divided by the factorial of its position number. Mathematical Formula Sum = 1/1! + 1/2! + 1/3! + ... + 1/n! Implementation const num = 5; const seriesSum = (n = 1) => { let sum = 0; let factorial = 1; for (let i = 1; i
Read More