Articles on Trending Technologies

Technical articles with clear explanations and examples

Explain common code blocks in JavaScript switch statement?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 328 Views

Common code blocks in JavaScript switch statements allow multiple cases to share the same execution code. This is achieved by omitting the break statement, causing execution to "fall through" to subsequent cases. What are Common Code Blocks? Common code blocks occur when multiple case values need to execute the same code. Instead of duplicating code, you can group cases together by omitting break statements. Syntax switch (expression) { case value1: case value2: case value3: // ...

Read More

Positive integer square array JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 393 Views

In JavaScript, we often need to filter arrays to extract specific types of numbers and perform operations on them. This example demonstrates how to find positive integers in an array and return the sum of their squares. Problem Statement Given an array containing various numbers (positive, negative, decimals, and integers), we need to write a function that returns the sum of squares of all positive integers only. Solution We'll use the reduce() method to iterate through the array and accumulate the sum of squares for positive integers: const arr = [1, -4, 6.1, 0.1, ...

Read More

Parse JSON in JavaScript to display a specific name/value pair?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 639 Views

To parse JSON in JavaScript, you can use the native JSON.parse() method or jQuery's parseJSON() function. To display specific name/value pairs, you can use array methods like forEach() or jQuery's $.each() function. Using Native JSON.parse() The modern approach uses the built-in JSON.parse() method: Parse JSON Example const APIData = '[{"Name":"John", "Age":21}, {"Name":"David", "Age":24}, {"Name":"Bob", ...

Read More

Sum of prime numbers between a range - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 623 Views

We are required to write a JavaScript function that takes in two numbers, say a and b and returns the sum of all the prime numbers that fall between a and b. We should include a and b if they are prime as well. Understanding Prime Numbers A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Examples include 2, 3, 5, 7, 11, 13, etc. Algorithm Overview To solve this problem, we need two functions: isPrime() - checks if a ...

Read More

How to display the selected option in a dropdown list with JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 33K+ Views

In this tutorial, we will learn how to display the selected option in a dropdown list with JavaScript. A dropdown list is a switchable menu that enables users to select one item from various options. It's created using the tag and is commonly used in forms to gather user input. The DOM API functions getElementById() and querySelector() can be used to access a element and retrieve its selected value. Let's explore the different methods to display the selected option. Using selectedIndex Property The selectedIndex property returns the index of the currently selected option in ...

Read More

How to fill columns with JavaScript?

Abhishek
Abhishek
Updated on 15-Mar-2026 801 Views

In this tutorial, we will learn how to fill columns with JavaScript using the columnFill property. This CSS property controls how content is distributed across multiple columns - either sequentially (auto) or with equal distribution (balance). The columnFill property specifies how columns should be filled when using CSS multi-column layout. It works in conjunction with columnCount to create responsive column layouts. Syntax Following is the syntax to set the columnFill property in JavaScript: selectedElement.style.columnFill = "value"; Here selectedElement is the DOM element you want to modify. The style property allows you to set ...

Read More

Storing Credentials in Local Storage

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 1K+ Views

Local Storage is designed for data that spans multiple windows and persists beyond the current session. Web applications can store megabytes of user data on the client side for performance reasons. However, storing credentials requires special security considerations. For secure credential storage, never store actual passwords or sensitive authentication data directly in local storage. Instead, use a token-based approach that minimizes security risks. Secure Token-Based Authentication On successful login, generate a completely random token string unrelated to user credentials. Store this token in your database with an expiry date, then pass it to JavaScript for local storage. ...

Read More

How to create multi-column layout in HTML5 using tables?

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

Design your webpage to display content across multiple columns using HTML tables. This approach allows you to create structured layouts with a main content area in the center, navigation menu on the left, and additional content like advertisements on the right. Basic Three-Column Layout Structure Tables provide a simple way to create multi-column layouts by using table rows () and table data cells (). Each cell acts as a separate column with customizable width and styling. Example Three Column HTML Layout ...

Read More

Usage of border-right-width property in CSS

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

The border-right-width property controls the thickness of an element's right border. It only works when a border style is defined. Syntax border-right-width: value; Values Value Description thin Thin border (usually 1px) medium Medium border (usually 3px) thick Thick border (usually 5px) length Custom width (px, em, rem, etc.) Example with Different Widths .box { ...

Read More

Explain Strict Comparison in JavaScript switch statement?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 481 Views

The JavaScript switch statement performs strict comparison (===) to match values. This means both value and type must be identical for a case to execute. If no strict match is found, the default case runs. Understanding Strict Comparison Strict comparison checks both value and type. For example, the number 1 is not equal to the string "1" in strict comparison: Strict Comparison Demo // Demonstrating strict vs loose comparison ...

Read More
Showing 17381–17390 of 61,297 articles
Advertisements