Javascript Articles

Page 412 of 534

Another method other than a constructor in a JavaScript class?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 303 Views

JavaScript classes support multiple types of methods beyond constructors. While constructors initialize objects, other methods provide functionality and behavior to class instances. The constructor is used to create and initialize an instance of a class. However, classes can contain additional methods that perform specific operations, calculations, or return formatted data. These methods are called on class instances and have access to the object's properties through the this keyword. Types of Methods in JavaScript Classes JavaScript classes support several method types: Instance methods: Called on class instances Static methods: Called on the class itself Getter/Setter methods: ...

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

Getters and setters in JavaScript classes?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 6K+ Views

In this article we are going to discuss about the getters and setters in JavaScript classes with suitable examples in JavaScript. In JavaScript, getters and setters are special methods that provide controlled access to object properties. They allow you to define custom behavior when getting or setting property values, ensuring data validation and encapsulation. Getters and setters use the get and set keywords respectively. Let's explore how to implement getters and setters in JavaScript classes and objects with practical examples. Syntax The basic syntax for getters and setters: class MyClass { ...

Read More

Weekday as a number in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 4K+ Views

In JavaScript, the getDay() method from the Date object returns the weekday as a number from 0 to 6, where Sunday is 0, Monday is 1, and so on. Syntax dateObject.getDay() The method returns an integer representing the day of the week: 0 = Sunday 1 = Monday 2 = Tuesday 3 = Wednesday 4 = Thursday 5 = Friday 6 = Saturday Example 1: Current Date Weekday Get the ...

Read More

Retrieve element from local storage in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 7K+ Views

To retrieve elements from local storage in JavaScript, we use the localStorage.getItem() method. Local storage provides persistent client-side data storage that remains available even after closing the browser. Local storage is a web API that allows you to store key-value pairs in a user's browser. Unlike session storage, data in local storage persists until explicitly removed or cleared by the user. This makes it ideal for storing user preferences, application state, or cached data. Local Storage Methods Local storage provides four main methods for data management: setItem(key, value) - Stores a key-value ...

Read More

How to check whether a number is finite or not in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 463 Views

In JavaScript, the isFinite() method checks whether a value is a finite number. It returns true for finite numbers and false for infinite values, NaN, or non-numeric values. Syntax isFinite(value) Parameters: value - The value to be tested for finiteness Return Value: Returns true if the value is finite, false otherwise. Example 1: Basic Usage Here's a function that demonstrates basic usage of isFinite(): Check Finite Numbers Checking division results: ...

Read More

How to encode a string in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 27K+ Views

In JavaScript, string encoding converts text into different formats for various purposes like URL handling, Base64 encoding, or data transmission. JavaScript provides several built-in methods for encoding strings depending on your specific needs. Encoding is the process of converting data from one format to another. Unlike encryption, encoding doesn't require keys and is primarily used to ensure data remains usable across different systems and protocols. Using btoa() Method The btoa() method encodes a string into Base64 format, which is commonly used for data transmission and storage. Syntax btoa(string) Where string is the text ...

Read More

Create many JavaScript objects as the same type?

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

In JavaScript, there are several ways to create multiple objects of the same type. JavaScript is a prototype-based object-oriented language, which means objects can inherit directly from other objects without needing traditional classes. This article explores various methods for creating objects with consistent structure and behavior. Using Constructor Functions Constructor functions are one of the most traditional ways to create multiple objects with the same structure. A constructor is simply a function that, when called with the new keyword, creates and returns a new object instance. Create many JavaScript objects as the same type ...

Read More

How to add a method to a JavaScript object?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 7K+ Views

In this article, we'll go over how to add a method to a JavaScript object in JavaScript with appropriate examples. A JavaScript object is an entity which has properties. A property can be a variable or a method which define state and behavior of the object. A method is a property of an object that adds behavior to an object. We can add a method to a JavaScript object using object prototype. All JavaScript objects get their attributes and methods from a prototype. Let's understand this concept better with the help of examples further in this article. ...

Read More

Add a property to a JavaScript object constructor?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 926 Views

In this article, we'll go over how to add properties to a JavaScript object constructor with appropriate examples. Adding a property to an object constructor is different from adding a property to a normal object. Properties must be added inside the constructor function itself, not outside. This ensures all instances created from the constructor have access to these properties. To get a better understanding, let's look at the syntax and usage of constructors in JavaScript. Syntax The syntax for a constructor is: function Constructor() { // No parameters } ...

Read More
Showing 4111–4120 of 5,340 articles
« Prev 1 410 411 412 413 414 534 Next »
Advertisements