Tag: JavaScript

TypeScript Setup

Below are the tools you need to set up with the environment to start writing TypeScript code: Node.js – Node.js is the environment in which you will run the TypeScript compiler. TypeScript compiler – a Node.js module that compiles TypeScript into JavaScript. If you use JavaScript for node.js, you can install the ts-node module. It is a TypeScript execution and REPL for node.js Visual Studio Code – It is a code editor that supports TypeScript. However, you can use your favourite editor. If you use VS Code, you can install the following extension to speed up the development process: Live Server...

Read More

Introduction to TypeScript

What is TypeScript A superset of JavaScript is TypeScript. The foundation for TypeScript is JavaScript. You begin by writing the TypeScript code. The TypeScript code is then converted into standard JavaScript code using a TypeScript compiler. Once you have the basic JavaScript code, you can use it anywhere JavaScript is supported. TypeScript files use the .ts extension rather than the .js extension of JavaScript files. In addition to using JavaScript syntaxes, TypeScript also introduces new syntaxes to support types. A TypeScript program is one that is written in JavaScript and doesn’t have any syntax errors. It means that all JavaScript programs are TypeScript...

Read More

Fill an Array with Initial Values in JavaScript

Arrays can be initialised with data in a variety of ways in JavaScript. Let’s examine which methods are the easiest and most popular in this post.   Read this blog post or watch the video below to learn more about different ways to fill an array with initial values in JavaScript. #1 Fill an array with primitives Let’s say, you want to initialize an array of elements 5 with the number 1. You can use the array.fill(initialValue) method to initialize an array. This method will return the modified array. The thing that you need to keep in mind is the...

Read More

Sparse vs Dense Arrays in JavaScript

Arrays in JavaScript is a very important concept. Developers are dealing with Arrays like creating, manipulating etc almost every day while implementing logics. Arrays are very easy to understand in JavaScript. An array is a special variable, which can hold more than one value But do you know that Arrays can hold nothing i.e. it is possible to create hole in an Array? In this post, I will be discussing about Sparse and Dense Arrays. Also I will be talking about how to create them and what you can do with this type of arrays. I have written a...

Read More

Group Arrays in JavaScript using Array.GroupBy

JavaScript continuously enriches its standard library on strings and arrays. In today’s post, I will be discussing the new array group proposal which is currently at stage 3. This new proposal introduces new methods array.groupBy() and array.groupByToMap(). You can get their polyfills from the core-js library. Let’s see examples below to understand how these methods work.   Read this blog post or watch the video below to learn more about the JavaScript array.groupBy() and array.groupByToMap() method. array.groupBy() Let’s say you have the below list of countries, where each country is an object with 2 properties name and continent. const countries =...

Read More