TypeScript Map (With Examples)

TypeScript Map is a new data structure that allows us to store data in the key-value pair and remembers the original insertion order of the keys. It is a new feature of ECMAScript 6 (ES6) that provides advantages over plain JavaScript objects. How to create a Map in TypeScript You can create a Map in TypeScript using this let … Read more

What is WebSocket and How to Implement It in JavaScript

Web socket protocol is being standardized, becoming a real-time communication between web servers and clients. In addition, web sockets are transforming to cross-platform standards for real-time client and server communication. Web sockets are defined as two-way communication between the servers and clients, which means both parties can communicate and exchange data at the same time. … Read more

How to Get Timestamp in JavaScript

To get a current timestamp in JavaScript, use the Date.now() function. The now() function gets the current timestamp by calling on the Date object. On UNIX-like machines, which include Linux and macOS, you can type the date +%s in the terminal and get the UNIX timestamp back. See the following code. console.log(Date.now()); Output We can get the … Read more

What is enums in TypeScript

Enums are a data type in TypeScript that allows you to define a set of named constants. It can be numeric or string-based. Enums cannot be used as variables; doing so would return errors. Enums are type-safe when you plan to reassign or modify the enum member values and would return compile errors on reassignment. Types … Read more

JavaScript Math max() Method

JavaScript Math.max() function is a static method that “returns the number with the highest value“. Syntax Math.max(x, y, z, …) Parameters The numbers out of which the maximum is to be determined. Return Value The maximum of all the parameters passed. If no argument is passed, this method returns negative infinity. If arguments cannot be … Read more

JavaScript String charCodeAt() Method

JavaScript String charCodeAt() method “returns the Unicode value of the character at the specified index in the string”. The index of the last character is string length – 1. Syntax string.charCodeAt(index) Parameters index: A number representing the index of the character you want to return. Return value The charCodeAt method returns “NaN” if there is no character … Read more

JavaScript Object.is() Method

JavaScript Object.is() method is “used to check if two values are the same”. Two values are the same if one of the following holds: Both are undefined Both are null Both are true, or both are false Both strings are of the same length with the same characters in the same order Both are the … Read more

JavaScript Object defineProperty() Method

JavaScript Object defineProperty() is a static method “used to define a new property on an object or modify an existing one and returns the object”. Syntax Object.defineProperty(obj, prop, descriptor) Parameters obj: The object on which to define the property. prop: The name or Symbol of the property to be defined or modified. descriptor: The descriptor for … Read more

5 Easy Ways to Flat an Array in JavaScript

There are the following methods to flat an array in JavaScript. Using Array.prototype.flat() method Using Array.prototype.reduce() method Using Array.prototype.concat() method Using a spread operator Using a recursive function Method 1: Use the Array.prototype.flat() method The best and most reliable way to flatten an array in JavaScript is to use the Array.prototype.flat() method. The Array flat() is … Read more

JavaScript String trimStart() and String trimEnd() Methods

JavaScript String trimStart() JavaScript String trimStart() method is “used to remove whitespace from the beginning of a string”. The following characters are the whitespace characters in JavaScript: A space character A tab character A carriage return character A new line character A vertical tab character A form feed character Syntax string.trimStart() Parameters None Return value … Read more

What is Strict Mode and How to Use It in JavaScript

Strict mode is a feature in JavaScript that enables stricter parsing and error handling of your code. By opting into the strict mode, you can catch common coding mistakes and “unsafe” actions, such as using undeclared variables, accidentally overwriting global objects, or using deprecated language features. To enable strict mode, you add the following directive … Read more