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
Object Oriented Programming Articles
Page 124 of 589
The yield* expression/keyword in JavaScript.
The yield* expression in JavaScript is used to delegate to another generator function or any iterable object. It yields all values from the delegated generator or iterable, effectively "flattening" nested generators. Syntax function* generatorFunction() { yield* anotherGenerator(); yield* iterableObject; } Basic Example: Delegating to Another Generator yield* Example yield* keyword in JavaScript CLICK ...
Read MoreNearest palindrome in JavaScript
We are required to write a function that takes in a number n and returns a palindromic number that is nearest to the number n. A palindrome reads the same forwards and backwards. For example: If the input number is 264, then the output should be 262 If the input number is 7834, then the output should be 7887 Approach The approach divides the number into two halves based on its length and creates a palindrome by mirroring the first half. For odd-length numbers, the middle digit remains unchanged. Example const ...
Read MoreThe debugger statement in JavaScript
The debugger statement in JavaScript is used to set a breakpoint in your code. When the JavaScript engine encounters this statement, it pauses execution and opens the browser's developer tools debugger (if available), allowing you to inspect variables, step through code, and debug issues. Syntax debugger; How It Works When the JavaScript engine hits a debugger statement: Execution pauses at that line Browser developer tools open automatically You can inspect the current scope, variables, and call stack If no debugger is available, the statement is ignored Example: Basic Debugging ...
Read MoreSorting JavaScript object by length of array properties.
In JavaScript, you can sort objects by the length of their array properties using the sort() method with a custom comparison function. This is useful when organizing data based on array sizes. Syntax array.sort((a, b) => a.property.length - b.property.length); Example: Sorting Students by Number of Subjects Sort by Array Length body { ...
Read MoreVowel, other characters and consonant difference in a string JavaScript
We are required to write a function that takes in a string of definite characters and the function should return the difference between the count of vowels plus other characters and consonants in the string. Problem Explanation For example, if the string is: "HEllo World!!" Then, we have 7 consonants, 3 vowels and 3 other characters here so the output should be: |7 - (3+3)| = 1 Hence, the output should be 1 Example const str = 'HEllo World!!'; const findDifference = str => { const creds ...
Read MoreHow to multiply two Arrays in JavaScript?
In JavaScript, multiplying two arrays means performing element-wise multiplication, where each element at the same index in both arrays is multiplied together. This creates a new array with the products. Element-wise Array Multiplication When multiplying arrays, we iterate through corresponding indices and multiply the values at those positions: Array Multiplication Multiply Two Arrays Multiply Arrays ...
Read MoreExplain 'Not a constructor function' error in JavaScript?
The "Not a constructor function" error occurs when we try to use the new keyword with a value that isn't a constructor function. This TypeError is thrown when JavaScript expects a constructor but receives a primitive value, object, or non-constructor function. What Causes This Error The error occurs when we attempt to instantiate something that cannot be used as a constructor: Primitive values (numbers, strings, booleans) Regular objects Arrow functions (in strict mode) Built-in methods that aren't constructors Example: Using Primitive as Constructor Constructor Error Demo ...
Read MoreReturn the difference between the maximum & minimum number formed out of the number n in JavaScript
We have to write a function that takes a positive number n and returns the difference between the maximum number and the minimum number that can be formed from its digits. For example, if the number n is 203: The maximum number that can be formed from its digits will be 320 The minimum number that can be formed from its digits will be 23 (placing the zero at one's place) And the difference will be: 320 - 23 = 297 Therefore, the output should ...
Read MoreHow to de-structure an imported object in JavaScript?
Destructuring allows you to extract specific properties from imported objects in JavaScript modules. This is particularly useful when you only need certain properties from a larger object. Basic Destructuring Syntax When importing an object, you can destructure it immediately or after import: // Method 1: Destructure after import import person from "./sample.js"; let {firstName, lastName, age} = person; // Method 2: Direct destructuring (named exports) import {firstName, lastName, age} from "./sample.js"; Example: Complete Implementation sample.js (Module file) export default { firstName: 'Rohan', ...
Read MoreReturn Top two elements from array JavaScript
We have an array of numbers in JavaScript that contains numbers in an unsorted order. Our job is to write a function that takes in this array of numbers and returns an array of two elements, the top two elements of the array (greatest two elements of the array). We have to do this in one pass i.e., we need to execute this method in linear time like by using only one for loop or if we use ES6 function, we have to make sure to use only one and once and avoid nesting of methods which increases time ...
Read More