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
Articles by Mayank Agarwal
Page 9 of 31
Stream writable.cork() and uncork() Method in Node.js
The writable.cork() method is used for forcing all written data to be buffered in memory. This buffered data will only be flushed when stream.uncork() or stream.end() methods are called. These methods are useful for optimizing performance by batching multiple write operations. Syntax cork() writable.cork() uncork() writable.uncork() Parameters Both methods take no parameters. The cork() method buffers subsequent write operations, while uncork() flushes the buffered data to the underlying destination. How It Works When cork() is called, all subsequent write operations are buffered in memory instead of being ...
Read MoreHow to swap variables using Destructuring Assignment in JavaScript?
The Destructuring assignment is a feature that was introduced in the ECMAScript 2015. This feature lets the user extract the contents of the array, and properties of an object into distinct variables without actually writing the repetitive code. This assignment lets the expression unpack values from arrays, and properties into distinct variables. One of the most elegant use cases is swapping variables without using a temporary variable. Traditional Variable Swapping Before destructuring, swapping variables required a temporary variable: Traditional Variable Swap ...
Read MoreStream writable.writableLength Property in Node.js
The writable.writableLength property returns the number of bytes (or objects) in the queue waiting to be written. This property is useful for monitoring buffer status and understanding the backpressure in your writable streams. Syntax writable.writableLength How It Works The property counts data that is: Buffered in the internal queue Waiting to be processed by the _write() method Corked (temporarily held) in memory Data that has already been written or is currently being processed is not counted. Example 1: Basic Usage with Cork Create a file named writableLength.js and run ...
Read MoreStream writable.writableObjectMode Property in Node.js
The writable.writableObjectMode property is used to check whether a writable stream is operating in object mode. It returns true if object mode is enabled, false if disabled, or undefined if not explicitly set. Syntax writable.writableObjectMode Return Value Returns a boolean value or undefined: true - Object mode is enabled false - Object mode is explicitly disabled undefined - Object mode not set (default) Example 1: Stream with Object Mode Enabled // Program to demonstrate writable.writableObjectMode property // Importing the stream module const stream = require('stream'); // Creating a ...
Read MoreHow to use Static Variables in JavaScript?
The keyword "static" is used for defining static methods or properties of a class in JavaScript. Static members belong to the class itself rather than to instances of the class, meaning you can access them without creating an object. Static variables maintain a single value that is shared across all instances of the class. Unlike instance variables, static variables are initialized when the class is first loaded and retain their value throughout the program's execution. Note − Static variables can be reassigned and modified, unlike const variables which are immutable after initialization. Syntax class ClassName ...
Read MoreHow to use the "in" operator in JavaScript?
In this article, we are going to explore the 'in' operator and how to use it in JavaScript. The in operator is an inbuilt operator in JavaScript that is used for checking whether a particular property exists in an object or not. It will return true if the property exists, else false is returned. Syntax prop in object Parameters This operator accepts the following parameters as described below − prop − This parameter holds the string or symbol that represents a property ...
Read MoreHow to Delete a Linked List in JavaScript?
In this article, we are going to explore Linked List and how to delete a linked list in JavaScript. A Linked List is a linear data structure where elements are not stored in contiguous memory locations. Each element (called a node) contains data and a pointer/reference to the next node in the sequence. ...
Read MoreWhat are JavaScript Classes and Proxies?
JavaScript Classes and Proxies are powerful ES6+ features that enhance object-oriented programming and metaprogramming capabilities. Classes provide a cleaner syntax for creating objects and implementing inheritance, while Proxies allow you to intercept and customize operations on objects. JavaScript Classes Classes in JavaScript are syntactic sugar over the existing prototype-based inheritance. They use the class keyword instead of functions and must be declared before use, unlike function declarations which are hoisted. Class Declaration Syntax class ClassName { constructor(property1, property2) { this.property1 = property1; ...
Read MoreWhat are JavaScript Factory Functions?
A factory function is a function that creates and returns an object. Unlike constructor functions, factory functions don't require the new keyword and don't use this to reference object properties. Factory functions are a simple and flexible way to create objects in JavaScript. They can include properties, methods, and default values, making object creation more convenient and reusable. Key Features Factory functions offer several advantages: No need for the new keyword No this binding issues Can contain private variables through closures Return objects directly Allow for easy object customization Basic Syntax ...
Read MoreWhat are the Important Array Methods in JavaScript?
In this article, we are going to explore different methods provided by Array and their importance in JavaScript. We will learn how to use them and what are their actual use cases with the help of examples. Before moving on to methods, below is the syntax for creating an array in JavaScript: let array = [element1, element2, ...]; Alternatively, we can also define the array as follows: let array = new Array(element1, element2, ...); Basic Array Methods (Adding/Removing Elements) These methods are essential for manipulating array contents: ...
Read More