Object Oriented Programming Articles

Page 86 of 589

How to find the href and target attributes in a link in JavaScript?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 7K+ Views

In JavaScript, you can access and manipulate the href and target attributes of anchor elements using DOM methods. These attributes control where links point and how they open. Finding href and target Attributes You can retrieve these attributes using getAttribute() or directly access them as properties of the anchor element. Finding href and target attributes TutorialsPoint let link = document.getElementById('myLink'); ...

Read More

What is the use of ()(parenthesis) brackets in accessing a function in JavaScript?

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

The parentheses () are crucial for function invocation in JavaScript. Accessing a function without parentheses returns the function reference, while using parentheses calls the function and returns its result. Function Reference vs Function Call When you write a function name without parentheses, JavaScript treats it as a reference to the function object. With parentheses, JavaScript executes the function. Without Parentheses - Function Reference Accessing a function without parentheses returns the function definition itself, not the result: function toCelsius(f) { return (5/9) * ...

Read More

Using a JavaScript object inside a static() method?

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

In JavaScript, static methods belong to the class itself, not to instances. You cannot directly access instance objects or use this inside static methods. However, you can pass objects as parameters to static methods to access their properties. Problem: Direct Object Access in Static Methods In the following example, trying to call a static method on an instance will result in an error because static methods should be called on the class, not the instance. class Company { constructor(branch) { ...

Read More

How to access 'this' keyword inside an arrow function in JavaScript?

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

The JavaScript 'this' keyword refers to the object it belongs to. Arrow functions handle 'this' differently than regular functions - they inherit 'this' from their surrounding scope rather than creating their own. How Arrow Functions Handle 'this' Arrow functions don't have their own 'this' binding. Instead, they capture the 'this' value from the enclosing lexical scope at the time they are defined. function Student(fname, grade) { this.fname = fname; this.grade = grade; this.details = function() { ...

Read More

"extends" keyword in JavaScript?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 1K+ Views

In JavaScript, the extends keyword enables class inheritance, allowing you to create child classes that inherit properties and methods from parent classes. This is a fundamental feature of ES6 classes that promotes code reusability and establishes clear hierarchical relationships between classes. Class inheritance allows you to build upon existing functionality without rewriting code. The child class automatically gains access to all public methods and properties of its parent class, while still being able to add its own unique features or override inherited behavior. Syntax class ChildClass extends ParentClass { // Child class ...

Read More

Get the first and last item in an array using JavaScript?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 370 Views

JavaScript arrays are 0-indexed, meaning the first element is at position 0 and the last element is at position length - 1. Here are several ways to access the first and last elements of an array. Using Index Access The most straightforward method uses bracket notation with index positions: let arr = [1, 'test', {}, 'hello', 42]; // First element console.log("First element:", arr[0]); // Last element console.log("Last element:", arr[arr.length - 1]); First element: 1 Last element: 42 Using Array Methods JavaScript provides built-in methods for accessing ...

Read More

Value of the class attribute node of an element in JavaScript?

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

JavaScript provides the getAttributeNode() method to retrieve the attribute node of an element as an attribute object. This method returns the attribute node with the specified name, or null if the attribute doesn't exist. Syntax element.getAttributeNode(attributename); It returns the attribute object representing the specified attribute node. To get the actual value, use the value property of the returned object. Example: Getting Class Attribute Value In this example, we have two heading tags with different classes. We'll use getAttributeNode() to retrieve the class attribute and display its value. ...

Read More

First element and last element in a JavaScript array?

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

An array is a group of elements where each element has its own index value. We can access any element using these indexes. For the first element, the index is always 0, but for the last element, we need to use the array's length property to calculate the correct index. Accessing the First Element Since arrays are zero-indexed in JavaScript, the first element is always at index 0. If the array is arr, then the first element is arr[0]. Example In the following example, we have two arrays and we'll access their first elements using index ...

Read More

JavaScript's Boolean function?

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

The Boolean() function in JavaScript converts any value to its boolean equivalent (true or false). This is useful for conditional checks and validation in your applications. Syntax Boolean(value); It takes any value or expression and returns true for truthy values and false for falsy values. Falsy Values These values always return false when converted to boolean: console.log(Boolean(0)); // false console.log(Boolean("")); // false (empty ...

Read More

How to access a JavaScript object using its own prototype?

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

JavaScript's Object.create() method creates a new object with the specified object as its prototype. This allows the new object to inherit properties from the existing object while maintaining a prototype chain. Syntax Object.create(prototypeObject); This method takes an existing object and creates a new object that inherits properties from it through the prototype chain. How It Works When you create an object using Object.create(), the new object doesn't copy the properties directly. Instead, it creates a prototype link to the original object, allowing property inheritance. var ...

Read More
Showing 851–860 of 5,881 articles
« Prev 1 84 85 86 87 88 589 Next »
Advertisements