Object Oriented Programming Articles

Page 111 of 589

Explain shorthand functions in JavaScript?

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

Arrow functions, also known as shorthand functions, were introduced in ES2015 and allow us to write functions in a shorter, more concise way. They don't have their own binding to this and inherit this from the surrounding context. Basic Syntax Arrow functions use the => syntax instead of the function keyword: // Regular function function add(a, b) { return a + b; } // Arrow function const add = (a, b) => a + b; Different Arrow Function Forms ...

Read More

How to embed JavaScript in HTML file?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 614 Views

There are three main ways to embed JavaScript in an HTML file: inline scripts, internal scripts, and external scripts. Each method serves different purposes and has its own advantages. Method 1: Inline JavaScript You can add JavaScript directly to HTML elements using event attributes: Inline JavaScript Inline JavaScript Example Click Me Method 2: Internal JavaScript Use the tag within the HTML document to ...

Read More

Explain Enumerated Types in JavaScript.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 205 Views

JavaScript doesn't support enums natively like other programming languages. However, you can implement enumerated types using objects to create named constants for better code readability and maintainability. Basic Enum Implementation The simplest way to create an enum is using a plain object with numeric values: JavaScript Enums Enumerated Types in JavaScript Show Color Values ...

Read More

How to disable mouse event on certain elements using JavaScript?

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

In JavaScript, you can disable mouse events on specific elements using the CSS pointer-events property. This technique prevents elements from receiving mouse clicks, hover effects, and other pointer interactions. Using pointer-events CSS Property The most effective method is setting pointer-events: none via JavaScript. This disables all mouse interactions on the target element. Disable Mouse Events body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; ...

Read More

Can we have a return statement in a JavaScript switch statement?

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

Yes, you can use return statements in a JavaScript switch statement, but only when the switch is inside a function. The return statement will immediately exit the function with the specified value, making break statements unnecessary. How Return Statements Work in Switch When a return statement is executed in a switch case, it immediately exits the function and returns the value. This eliminates the need for break statements since the function execution stops. Example: Day Name Function Return ...

Read More

How to turn words into whole numbers JavaScript?

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

We need to write a function that takes a string of number words as input and converts them into their equivalent whole number. Problem Overview Given a string containing number words separated by spaces, we want to convert each word to its corresponding digit and combine them into a single number. "one five seven eight" -------> 1578 "two eight eight eight" -------> 2888 Approach The solution involves creating a mapping of number words to digits, then iterating through each word to build the final number. We split the input string by whitespace ...

Read More

Named arguments in JavaScript.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 286 Views

Named arguments in JavaScript allow you to pass parameters to functions using an object, making function calls more readable and flexible. This technique uses object destructuring to extract named properties from the passed argument. Syntax function functionName({ param1, param2, param3 }) { // Function body } // Call with named arguments functionName({ param1: value1, param2: value2, param3: value3 }); Basic Example Named Arguments Example Named ...

Read More

JavaScript program to take in a binary number as a string and returns its numerical equivalent in base 10

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 321 Views

We are required to write a JavaScript function that takes in a binary number as a string and returns its numerical equivalent in base 10. Therefore, let's write the code for the function. This one is quite simple, we iterate over the string using a for loop and for each passing bit, we double the number with adding the current bit value to it like this − Example const binaryToDecimal = binaryStr => { let num = 0; for(let i = 0; i < binaryStr.length; i++){ ...

Read More

How to load a JavaScript file Dynamically?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 701 Views

Loading JavaScript files dynamically allows you to add scripts to your webpage at runtime, which is useful for conditional loading, lazy loading, or modular applications. Basic Dynamic Loading Method The most common approach is creating a element and appending it to the document head: Dynamic JavaScript Loading body { font-family: "Segoe UI", Tahoma, ...

Read More

How can I remove a child node in HTML using JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 257 Views

In JavaScript, you can remove child nodes from HTML elements using several methods. The most common approaches are removeChild() and the modern remove() method. Using removeChild() Method The removeChild() method removes a specified child node from its parent element. You need to call it on the parent element and pass the child node as a parameter. Remove Child Node body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result ...

Read More
Showing 1101–1110 of 5,881 articles
« Prev 1 109 110 111 112 113 589 Next »
Advertisements