Web Development Articles

Page 449 of 801

Implementation of Stack in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 536 Views

A stack is a Last In First Out (LIFO) data structure where elements are added and removed from the same end, called the top. This article demonstrates how to implement a stack in JavaScript using a class-based approach with basic operations like push, pop, and display. What is a Stack? A stack follows the LIFO principle - the last element added is the first one to be removed. Think of it like a stack of plates where you can only add or remove plates from the top. Item 3 ...

Read More

Shared properties in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 445 Views

In JavaScript, properties can be shared across all instances of an object by attaching them to the constructor function's prototype property. This creates a single shared property that all instances can access, rather than each instance having its own copy. How Prototype Properties Work When you access a property on an object, JavaScript first checks if the property exists on the instance itself. If not found, it looks up the prototype chain to find the property on the constructor's prototype. Student.prototype school: "St Marks" ...

Read More

Share methods in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 708 Views

Methods can be shared across multiple object instances by attaching them to the prototype property. This approach ensures all instances of a constructor function share the same method, making memory usage more efficient than defining methods inside the constructor. Basic Prototype Method Sharing When you define a method on the prototype, all instances created from that constructor function can access it: Shared Methods Shared Methods in JavaScript ...

Read More

Creating an associative array in JavaScript with push()?

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

An associative array in JavaScript is essentially an object that uses string keys to store arrays of values. You can create this structure by combining forEach() loops with the push() method to group related data. Example: Grouping Students by ID Here's how to create an associative array that groups student names by their student ID: var studentDetails = [ { studentId: 1, studentName: "John" }, { ...

Read More

Static Properties in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 189 Views

Static properties in JavaScript belong to the class itself rather than its instances. They can be accessed directly on the class without creating objects, making them useful for storing class-level data like constants or shared values. Syntax // Function constructor approach function ClassName(params) { // instance properties } ClassName.staticProperty = value; // ES6 class approach class ClassName { static staticProperty = value; } Example: Static Properties with Function Constructor ...

Read More

How to check if an object is an instance of a Class in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 468 Views

In JavaScript, you can check if an object is an instance of a specific class using the instanceof operator. This operator returns true if the object was created by the specified constructor function or class. Syntax object instanceof Constructor Using instanceof with Constructor Functions Instance Check Example CHECK INSTANCE function Student(name, age, standard) { this.name = name; this.age = age; this.standard = standard; } let student1 = new Student("Rohan", ...

Read More

How to get key name when the value contains empty in an object with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 889 Views

To find keys with empty values in a JavaScript object, you can use Object.keys() combined with find() or filter(). This is useful for form validation or data cleaning. Let's say we have the following object: var details = { firstName: 'John', lastName: '', countryName: 'US' }; Using Object.keys() with find() To find the first key with an empty value, use Object.keys() along with find(): var details = { firstName: 'John', lastName: '', countryName: 'US' ...

Read More

Dot notation in JavaScript

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

Dot notation is the most common way to access object properties in JavaScript. It uses a dot (.) between the object name and property name to retrieve or set values. Syntax objectName.propertyName Basic Example Dot Notation Example Student Information Show Student Details function Student(name, age, standard) { ...

Read More

Dot notation vs Bracket notation in JavaScript

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

The dot notation and bracket notation are both methods for accessing object properties in JavaScript. While dot notation is cleaner and more commonly used, bracket notation provides greater flexibility, especially when working with dynamic property names or property names that contain special characters. Syntax Here's the basic syntax for both notations: // Dot notation object.propertyName // Bracket notation object["propertyName"] object[variableName] Basic Example: Accessing Properties Dot vs Bracket Notation ...

Read More

Setting object members in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 157 Views

In JavaScript, you can set object members (properties and methods) in several ways. This allows you to dynamically add or modify object properties after creation. Syntax // Dot notation object.propertyName = value; // Bracket notation object["propertyName"] = value; // Setting methods object.methodName = function() { // method body }; Example: Setting Object Properties Setting Object Members ...

Read More
Showing 4481–4490 of 8,010 articles
« Prev 1 447 448 449 450 451 801 Next »
Advertisements