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 3 of 31
How to chain asynchronous functions in JavaScript?
JavaScript is a single-threaded language that executes operations synchronously by default. Synchronous operations can be time-consuming and block other operations in the thread. JavaScript provides asynchronous programming capabilities that allow functions to execute without blocking other operations. This is achieved through asynchronous constructs like Promises, async/await, and callbacks. Asynchronous functions are powerful, but their unpredictable execution timing can create challenges. Chaining these functions ensures they execute in a specific order, making your code more predictable and easier to debug. In this article, we will explore different methods for chaining asynchronous functions using modern JavaScript features. The ...
Read Morecrypto.createDiffieHellman() Method in Node.js
The crypto.createDiffieHellman() method in Node.js creates a Diffie-Hellman key exchange object using a specified prime value and an optional generator. This method enables secure key exchange between two parties over an insecure channel. Syntax crypto.createDiffieHellman(prime, [primeEncoding], [generator], [generatorEncoding]) Parameters prime – The prime number used for the Diffie-Hellman exchange. Can be a number (bit length) or Buffer/string containing the prime value. primeEncoding ...
Read Morecrypto.createDiffieHellman(primeLength, [generator]) Method in Node.js
The crypto.createDiffieHellman(primeLength, [generator]) method creates a Diffie-Hellman key exchange object by generating a prime number of specified bit length. This is commonly used for secure key exchange between parties. Syntax crypto.createDiffieHellman(primeLength, [generator]) Parameters The parameters are described below: primeLength – The number of prime bits to generate. Must be a number. generator – Optional generator for creating the exchange key object. ...
Read MoreJavaScript: How to check whether an array includes a particular value or not?
In JavaScript, there are several ways to check whether an array includes a particular value. This article explores different approaches to search for values in arrays effectively. Array Creation Syntax let array = [arrayItem1, arrayItem2, arrayItem3, ...]; Using for Loop (Traditional Approach) The traditional approach involves looping through all array elements and comparing each value with the target value. This method also allows you to find the index of the element. Array Value Check ...
Read Morecrypto.createHash() Method in Node.js
The crypto.createHash() method creates a hash object that can generate hash digests using cryptographic algorithms like SHA-256, MD5, or SHA-512. It's commonly used for password hashing, data integrity verification, and digital signatures. Syntax crypto.createHash(algorithm, [options]) Parameters algorithm – The hashing algorithm to use (string). Common values: 'sha256', 'md5', 'sha512', 'sha1' options – Optional parameters for controlling stream behavior and output length for certain algorithms Return Value Returns a Hash object that can be used to generate hash digests by chaining update() and digest() methods. Example 1: Basic Hash Generation ...
Read MoreHow to compile a Typescript file?
In this article we are going to explore TypeScript and how to compile and execute TypeScript files. TypeScript is an open-source programming language developed and maintained by Microsoft. TypeScript is syntactically similar to JavaScript but adds additional features like static typing and object-oriented programming. Unlike JavaScript, TypeScript does not run directly in web browsers and must be compiled to JavaScript first. TypeScript files need to be transpiled to JavaScript before they can be executed. This compilation process converts TypeScript syntax into standard JavaScript that browsers and Node.js can understand. Prerequisites Before compiling TypeScript files, you need ...
Read Morecrypto.createHmac() Method in Node.js
The crypto.createHmac() method creates and returns an HMAC (Hash-based Message Authentication Code) object in Node.js. This method uses a specified algorithm and secret key to generate cryptographic hashes for data integrity and authentication purposes. Syntax crypto.createHmac(algorithm, key, [options]) Parameters algorithm – The hashing algorithm to use (e.g., 'sha256', 'sha1', 'md5'). Input type is string. key – The secret key used for generating the cryptographic HMAC hash. Can be a string, Buffer, TypedArray, or DataView. options – Optional parameters for controlling stream ...
Read Morecrypto.pbkdf2() Method in Node.js
The crypto.pbkdf2() method in Node.js implements the Password-Based Key Derivation Function 2 (PBKDF2) algorithm. It derives a cryptographic key from a password using a salt and multiple iterations to enhance security against brute-force attacks. Syntax crypto.pbkdf2(password, salt, iterations, keylen, digest, callback) Parameters The parameters are described as follows: password – The password string used for key derivation. Accepts string, Buffer, TypedArray, or DataView. ...
Read MoreHow to convert a string of any base to an integer in JavaScript?
An integer can be represented in various formats in programming languages such as Binary (base 2), Decimal (base 10), Hexadecimal (base 16), and Octal (base 8). A Binary number consists of two digits only (0 & 1), whereas a decimal consists of digits from 0 to 9. We can convert a string to an integer using the parseInt() method. When the integer is represented in a different base, we need to pass the base parameter to decode it correctly. Syntax parseInt(string_value, base) parseInt(string_value) // Defaults to base 10 Parameters ...
Read Morecrypto.randomBytes() Method in Node.js
The crypto.randomBytes() method generates cryptographically strong pseudo-random data in Node.js. This method ensures sufficient entropy before completion, typically taking only a few milliseconds to generate secure random bytes. Syntax crypto.randomBytes(size, [callback]) Parameters The parameters are described below: size – Specifies the number of bytes to generate. Must not exceed 2**31 - 1. callback – Optional callback function called if an error occurs. If omitted, the method runs synchronously. Asynchronous Example ...
Read More