Object Oriented Programming Articles

Page 115 of 589

How to check whether a Button is clicked with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

In JavaScript, you can detect button clicks using event listeners. The addEventListener() method is the standard approach to handle click events and track user interactions. Basic Click Detection The most common way to check if a button is clicked is using the click event: Button Click Detection body { font-family: "Segoe UI", Tahoma, Geneva, ...

Read More

What are the uses of the JavaScript WITH statement?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

The WITH statement is used to specify the default object for the given property and allow us to prevent writing long lengthy object references. It adds the given object to the head of the scope chain. Important: The with statement is deprecated and not recommended in modern JavaScript. It's disabled in strict mode and can cause performance and security issues. Syntax with (object) { // statements } Basic Example Here's how the with statement works with a simple object: ...

Read More

Get minimum number without a Math function JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 312 Views

We need to find the smallest number from a set of numbers without using JavaScript's built-in Math.min() function. This requires implementing our own comparison logic. Approach Using While Loop We'll iterate through all numbers and keep track of the smallest value found so far, updating it whenever we encounter a smaller number. Example const numbers = [12, 5, 7, 43, -32, -323, 5, 6, 7, 767, 23, 7]; const findMin = (...numbers) => { let min = Infinity, len = 0; while(len < numbers.length) { ...

Read More

How to get the child element of a parent using JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 644 Views

JavaScript provides several methods to access child elements of a parent element. The most common approaches include using children, childNodes, querySelector, and querySelectorAll. Using the children Property The children property returns a live HTMLCollection of all direct child elements, excluding text nodes and comments. Getting Child Elements body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .child1, .child2, .child3 { display: none; ...

Read More

Can I verify if a JavaScript variable is loaded if so, how?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

To verify if a JavaScript variable has been loaded or initialized, you can check if it is undefined or has a null value. JavaScript provides several methods to perform this check effectively. The most common approaches include direct comparison with undefined and null, using the typeof operator, or checking if the variable exists in a specific scope. Method 1: Using Direct Comparison This method checks if a variable is undefined or null using strict equality: Variable Check Example ...

Read More

How to pass arguments to anonymous functions in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

Anonymous functions in JavaScript are functions without a name that can accept parameters just like regular functions. You can pass arguments to them through function calls, event handlers, or higher-order functions. What are Anonymous Functions? Anonymous functions are functions declared without a name. They're often assigned to variables or used as callback functions. Anonymous Functions Anonymous Function Examples Run Examples ...

Read More

What's the best way to open new browser window using JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 314 Views

The window.open() method is the standard way to open new browser windows in JavaScript. It provides control over window features and behavior. Syntax window.open(url, name, features) Parameters url: The URL to open (optional) name: Window name or target (optional) features: Window features like size, position, toolbar (optional) Basic Example Open New Window body { ...

Read More

Check if some elements of array are equal JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 434 Views

We have an array of numbers that have got some redundant entries, our job is to write a function that takes in the array and groups all the identical entries into one subarray and returns the new array thus formed. For example − //If the input array is: const arr = [1, 3, 3, 1]; //then the output should be: const output = [[1, 1], [3, 3]]; We will use a HashMap to keep a track of the elements already occurred and iterate over the array using a for loop. Using HashMap Approach ...

Read More

JavaScript to parse and show current time stamp of an HTML audio player.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

The HTML audio element provides a currentTime property that returns the current playback position in seconds. We can parse this value to display minutes and seconds separately. HTML Audio currentTime Property The currentTime property returns a floating-point number representing the current playback time in seconds. We can use Math.floor() to convert it into readable minutes and seconds format. Example Audio Timestamp Parser body { ...

Read More

How do I recursively remove consecutive duplicate elements from an array?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 708 Views

Suppose, we have an array of Number literals that contains some consecutive redundant entries like this: const testArr = [1, 1, 2, 2, 3, 3, 1, 1, 1]; We are supposed to write a function compress that takes in this array and removes all redundant consecutive entries in place. So that the output looks like this: const output = [1, 2, 3, 1]; Let's write the code for this function using recursion to remove consecutive duplicate elements. Recursive Approach The recursive function works by traversing the array and comparing each ...

Read More
Showing 1141–1150 of 5,881 articles
« Prev 1 113 114 115 116 117 589 Next »
Advertisements