Javascript Articles

Page 403 of 534

Write a number array and using for loop add only even numbers in javascript?

Vivek Verma
Vivek Verma
Updated on 15-Mar-2026 2K+ Views

In JavaScript, you can iterate through a number array and add only the even numbers using various loop methods. An even number is any integer that is divisible by 2, meaning when divided by 2, the remainder is 0. What are Even Numbers? Even numbers are integers that can be divided by 2 without leaving a remainder. We can check this using the modulo operator (%): if(number % 2 == 0) { // Number is even } Using for Loop The for loop is the most common way to iterate ...

Read More

How to display output in javascript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 3K+ Views

JavaScript provides several methods to display output to users. Here are the four most common approaches for displaying data in web applications. Using innerHTML to Display in HTML Elements The innerHTML property allows you to insert content directly into HTML elements on your webpage. document.getElementById("demo").innerHTML = "Hello, World!"; Hello, World! Using document.write() Method The document.write() method writes content directly to the HTML document. ...

Read More

Write the syntax of javascript with a code to demonstrate it?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 270 Views

JavaScript Tags JavaScript code must be placed within HTML tags to execute properly. These script tags can be positioned in different locations within an HTML document. Where to Place JavaScript JavaScript can be embedded in three main locations: Head section: Scripts in the tag load before the page content Body section: Scripts in the tag execute as the page loads External file: Scripts can be linked from separate .js files Basic JavaScript Syntax JavaScript syntax includes variables, functions, and DOM ...

Read More

What are the types of tags involved in javascript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 1K+ Views

In JavaScript, there are several types of HTML tags that work with JavaScript code. The most important is the tag, which is essential for embedding or linking JavaScript in web pages. HTML Tag The tag is used to define client-side scripts in HTML documents. It can contain JavaScript code directly or reference an external JavaScript file. All JavaScript code must be placed within tags to be executed by the browser. Types of Script Tags Inline JavaScript JavaScript code written directly inside the tag: ...

Read More

How to execute a cube of numbers of a given array in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 2K+ Views

To calculate the cube of each number in an array, you can use several approaches. The most common methods involve iterating through the array and applying the cube operation (n³) to each element. Using a for Loop The traditional approach uses a for loop to iterate through the array and replace each element with its cube: var numbers = [1, 2, 3, 4, 5]; // Calculate cube of each element for (var i = 0; i ...

Read More

How to find the minimum value of an array in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 3K+ Views

JavaScript provides several methods to find the minimum value in an array. The most efficient approach is using Math.min() with the spread operator, though other methods like sorting are also available. Using Math.min() with Spread Operator (Recommended) The Math.min() function finds the smallest number among its arguments. Combined with the spread operator (...), it can easily find the minimum value in an array. Find Minimum function findMinimum() { var numbers = [6, 39, 55, 1, 44]; var minimum = Math.min(...numbers); ...

Read More

What is the difference between Math.ceil() and Math.round() methods in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 6K+ Views

Math.ceil() and Math.round() are JavaScript methods that round numbers to integers, but they work differently. Math.ceil() always rounds up to the nearest integer, while Math.round() rounds to the nearest integer using standard rounding rules (0.5 and above rounds up, below 0.5 rounds down). Math.ceil() - Always Rounds Up The Math.ceil() method rounds a number up to the nearest integer, regardless of the decimal value. It always moves toward the greater value. Syntax Math.ceil(x) Example ...

Read More

Explain in detail about the memory life cycle of JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 473 Views

JavaScript's memory management is crucial for application performance. Understanding the memory lifecycle helps developers write more efficient code and avoid memory leaks. The Three Stages of Memory Lifecycle Every programming language follows a similar memory lifecycle with three fundamental stages: Allocation of memory - Reserve memory space for variables and objects Use the allocated memory - Read from and write to the allocated memory Release the allocated memory - Free up memory when it's no longer needed In low-level languages, developers manually handle allocation and deallocation. However, high-level languages like JavaScript manage this process ...

Read More

Explain in detail about Reference-counting garbage collection in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 3K+ Views

Reference-counting garbage collection is the simplest garbage collection algorithm used in JavaScript. This algorithm monitors objects and removes those that have no references pointing to them. An object becomes eligible for garbage collection when its reference count drops to zero. How Reference-Counting Works The algorithm maintains a count of how many references point to each object. When a reference is created, the count increases. When a reference is removed, the count decreases. Objects with zero references are immediately marked for garbage collection. Example: Basic Reference Counting var obj = { x: ...

Read More

How to implement merge sort in JavaScript?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 9K+ Views

The Merge Sort algorithm is a divide-and-conquer sorting technique that recursively divides an array into smaller subarrays until each contains a single element, then merges them back in sorted order. The algorithm works by continuously splitting the array in half until it cannot be divided further. Once we have individual elements, we merge them back together in a sorted manner, comparing elements from each subarray and placing them in the correct order. Input-output Scenario Consider an unsorted array that we want to sort using merge sort: Input = [12, 34, 11, 1, 54, 25, 67, ...

Read More
Showing 4021–4030 of 5,340 articles
« Prev 1 401 402 403 404 405 534 Next »
Advertisements