Shriansh Kumar

Shriansh Kumar

211 Articles Published

Articles by Shriansh Kumar

211 articles

JavaScript Program for Left Rotation and Right Rotation of a String

Shriansh Kumar
Shriansh Kumar
Updated on 15-Mar-2026 1K+ Views

To implement left rotation and right rotation of a string, we can use various approaches. Left rotation means moving characters counter-clockwise by a given number of positions, while right rotation means moving characters clockwise by a given number of positions. In this article we have a string and a value of k by which we will rotate the string. Our task is to write a JavaScript program for left rotation and right rotation of a string. Example Input: String str = "apple"; k = 3 Output: Left Rotation: "leapp" Right Rotation: "pleap" Approaches ...

Read More

JavaScript in filter an associative array with another array

Shriansh Kumar
Shriansh Kumar
Updated on 15-Mar-2026 1K+ Views

In this article, we'll explore how to filter an associative array using another array in JavaScript. This is a common task when you need to extract specific objects from a dataset based on matching criteria. What is an Associative Array? An associative array is a data structure that stores key-value pairs. Each key is associated with a specific value and serves as a unique identifier. Unlike regular arrays, associative arrays don't use numeric indexes—keys can be strings or numbers. In JavaScript, objects function as associative arrays since they store key-value pairs where keys can be strings or ...

Read More

JavaScript: How to check if a number is even without using the modulo operator?

Shriansh Kumar
Shriansh Kumar
Updated on 15-Mar-2026 1K+ Views

For a given integer number, write a program in JavaScript to check whether a number is odd or even and return the same to the user. It's pretty easy to check whether a number is even by using the modulo operator. But, in this article, we will be checking whether a number is even or not without using the modulo operator. Using the For Loop In this approach, we are going to use the for loop to check whether a number is even or not. The idea is to take a Boolean flag variable as true and toggle ...

Read More

JavaScript Program to Check if a Given Year is Leap Year

Shriansh Kumar
Shriansh Kumar
Updated on 15-Mar-2026 2K+ Views

To check if a given year is leap year, we have used two approaches in this article. A leap year has 366 days. In every 4th year, an additional day is added to the month of February to synchronize it with the astronomical year. In this article, we are given with two years to check. Our task is to write a JavaScript program to check if a given year is leap year. Leap Year Rules A year is considered a leap year if it follows these rules: Divisible by 4 AND not divisible ...

Read More

JavaScript clearTimeout() & clearInterval() Method

Shriansh Kumar
Shriansh Kumar
Updated on 15-Mar-2026 2K+ Views

In JavaScript, the clearTimeout() and clearInterval() methods are used to clear timers. When we set a timer using setTimeout() or setInterval() methods, the browser allocates memory to track it. Therefore, we use these methods to release that memory and avoid unnecessary function calls. It is best practice to clear timers when they are no longer needed to prevent memory leaks and unwanted executions. JavaScript clearTimeout() Method The clearTimeout() method clears a timeout that was previously set by setTimeout(). It prevents the scheduled function from executing if called before the timeout completes. Syntax clearTimeout(timeoutID) Parameters ...

Read More

JavaScript program to retrieve clients IP address

Shriansh Kumar
Shriansh Kumar
Updated on 15-Mar-2026 1K+ Views

Internet Protocol address, in short, IP address, is a unique address represented by a string of numbers that identifies a device on the internet or a local network. In JavaScript, we can retrieve a client's IP addresses using 3rd party API services such as ipify or ipapi. We can then further use this information to track user locations, personalize content based on the location, or implement security measures. Understanding Client-Side IP Detection JavaScript running in the browser cannot directly access the client's IP address due to security restrictions. However, we can use external APIs that return the public ...

Read More

JavaScript function to take a number n and generate an array with first n prime numbers

Shriansh Kumar
Shriansh Kumar
Updated on 15-Mar-2026 2K+ Views

We are required to write a JavaScript function that takes in a number n and returns an array that contains first n prime numbers. We know that prime numbers are those numbers that are only divisible by 1 and themselves like 2, 3, 19, 37, 73 etc. Let's understand the problem with an example − Input: n = 6; Output: prime_numbers = [ 2, 3, 5, 7, 11, 13 ] Using Iteration We will first write a function that checks whether a given number is prime or not and then run a loop ...

Read More

JavaScript how to get an alert to appear when I click on a button in a class?

Shriansh Kumar
Shriansh Kumar
Updated on 15-Mar-2026 2K+ Views

An alert in JavaScript is a dialog box that displays important information or warnings to the user. It contains a message with an OK button that dismisses the dialog when clicked. Clicking a button triggers an event handler that invokes a function instructing the browser to display the alert dialog. In this article, we will explore different ways to show an alert when a user clicks on a button in a class. For example, click on the button below to see an alert: .alerttoappear { margin: auto; width: ...

Read More

Difference Between JSP and PHP

Shriansh Kumar
Shriansh Kumar
Updated on 15-Mar-2026 1K+ Views

Both JSP and PHP are two popular technologies that serve to create dynamic web pages. Both are similar in the ways that they allow developers to embed code within an HTML document that can interact with databases, sessions, cookies, and other web features. However, they also have some significant differences that may affect the choice of which one to use for a web project. In this article, we will explore the difference between JSP and PHP in terms of their syntax, performance, scalability, security, and compatibility. What is JSP? JSP stands for Java Server Pages and is used ...

Read More

Why an interface doesn\'t have a constructor whereas an abstract class have a constructor in Java?

Shriansh Kumar
Shriansh Kumar
Updated on 01-Sep-2025 9K+ Views

Interfaces in Java are used for defining a contract that classes can implement. They can contain method signatures, default methods, static methods, and constants. we must implement the methods defined in the interface in the implementing class. Constructor in an Interface A Constructor is to initialize the non-static members of a particular class with respect to an object. An Interface in Java doesn't have a constructor because all data members in interfaces are public static final by default, they are constants (assign the values at the time of declaration). There are ...

Read More
Showing 1–10 of 211 articles
« Prev 1 2 3 4 5 22 Next »
Advertisements