Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Javascript Articles
Page 443 of 534
How to pass event objects from one function to another in JavaScript?
In JavaScript, event objects contain information about user interactions like clicks, key presses, or mouse movements. You can pass these event objects between functions to share event data and manipulate the same target element across multiple functions. Syntax // Function that receives event and passes it to another function firstFunction(event) { // Do something with event secondFunction(event); // Pass event to another function } function secondFunction(event) { // Use the same event object event.target.style.property = "value"; } ...
Read MoreHow do we loop through array of arrays containing objects in JavaScript?
In JavaScript, when working with nested arrays containing objects, you need to use nested loops to access each object's properties. This tutorial demonstrates multiple approaches to iterate through such complex data structures. Understanding the Data Structure An array of arrays containing objects has this structure: let arrObj = [ [ { name: "Rohan", age: 22 }, { name: "Mohan", age: 12 } ], [ ...
Read MoreImplementation of Stack in JavaScript
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 MoreShared properties in JavaScript
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 MoreShare methods in JavaScript
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 MoreStatic Properties in JavaScript
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 MoreHow to check if an object is an instance of a Class in JavaScript?
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 MoreDot notation in JavaScript
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 MoreDot notation vs Bracket notation in JavaScript
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 MoreSetting object members in JavaScript
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