Object Oriented Programming Articles

Page 79 of 589

In JavaScript inheritance how to differentiate Object.create vs new?

Abhinanda Shri
Abhinanda Shri
Updated on 15-Mar-2026 229 Views

In JavaScript inheritance, Object.create() and new serve different purposes when setting up prototype chains. Understanding their differences is crucial for proper inheritance implementation. Object.create() - Prototype Only Inheritance When using Object.create(), you inherit only the prototype methods without executing the parent constructor: function BaseClass(name) { this.name = name; console.log("BaseClass constructor called"); } BaseClass.prototype.greet = function() { return "Hello from " + this.name; }; function ChildClass(name) { this.name = name; } // Using Object.create - inherits prototype only ...

Read More

Is there a way to add/remove several classes in one single instruction with classList in HTML and JavaScript?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 272 Views

The classList property returns the class names of an element as a DOMTokenList object. While it's read-only, you can modify it using methods like add() and remove(). The classList property automatically prevents duplicate classes from being added. You can add or remove multiple classes in a single instruction using several approaches. Using Multiple Parameters (ES6+) Modern browsers support passing multiple class names as separate parameters: Content const element = document.getElementById('myDiv'); // Add multiple classes element.classList.add('active', 'highlighted', 'primary'); console.log(element.className); // Remove multiple classes element.classList.remove('active', 'highlighted'); console.log(element.className); container active ...

Read More

Write a number array and add only odd numbers?

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

In JavaScript, you can sum only the odd numbers from an array by using the modulus operator (%) to check if a number is odd, then adding it to a running total. How It Works The modulus operator returns the remainder when a number is divided by 2. If the remainder is not equal to 0, the number is odd. Example: Summing Odd Numbers var tot = 0; var a = [1, 45, 78, 9, 78, 40, 67, 76]; ...

Read More

Write the main difference between '==' and '===' operators in javascript?

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

The main difference between == and === operators in JavaScript is that == performs type coercion (converts types before comparing), while === performs strict comparison without any type conversion. The == Operator (Loose Equality) The == operator compares values after converting them to the same type if needed. This can lead to unexpected results. Example var x = 5; var y = "5"; var z = 6; document.getElementById("loose").innerHTML = (x == y) + "" + (x == z); Output true false Notice ...

Read More

what is the main difference between '=' and '==' operators in javascript?

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

In JavaScript, the = operator is used for assignment, while the == operator is used for equality comparison. Understanding this difference is fundamental to writing correct JavaScript code. The Assignment Operator (=) The = operator assigns a value from the right side to the variable on the left side. It does not compare values. var x = 5; // Assigns 5 to variable x var y = "6"; // Assigns string "6" to variable y var z = x; ...

Read More

Explain about logical not(!) operator in detail with example in javascript?

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

The logical NOT operator (!) is a unary operator that inverts boolean values. It returns true for falsy values and false for truthy values. Syntax !expression How It Works The NOT operator first converts the operand to a boolean value, then returns its opposite: If the operand is truthy, it returns false If the operand is falsy, it returns true Example with Boolean Values document.getElementById("boolean-demo").innerHTML = "!true = " + !true ...

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 275 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
Showing 781–790 of 5,881 articles
« Prev 1 77 78 79 80 81 589 Next »
Advertisements