When I review a code, I see people keep mixing for and forEach in their code. Either they are confused, or they can’t differentiate between for and forEach. As a thumbs rule, You should always use forEach except for a few scenarios. Here in this article, I will explain when you should make those exceptions. This is valid for Array.map
also.
Before going further let’s have a quick look at both of the syntaxes.
For Loop:
for ([initialExpression]; [conditionExpression];[incrementExpression]) {
statement|s
}const array = [1, 2, 3, 4, 5]; for (let index = 0; index < array.length; index++) {…
JS|TS By Example
You work on multiple projects. Most of the time you repeat your self while writing common util functions. Here are some of the most useful utilities that you can use for your TypeScript or JavaScript
1. compact: Compact is normally used to remove the falsy value from an Array. There are multiple variations of it.
Simple Variant: filter out falsy values (false
, null
, 0
, ""
, undefined
, and NaN
).
// Code:
const compact = (arr = []) => arr.filter(Boolean);// How to use it compact([0, 1, false, 2, "", 3, "a", Number("e") * 23, NaN, "s", 34]); //…
For the past few years, I have almost stopped writing JavaScript. You may ask why. It doesn't mean I don't like JavaScript. However, there is a better version of JavaScript, TypeScript. Yes, I have started developing all my library and application in TypeScript. It includes the backend too.
Here in this article, I will try to answer the question of why you should use TypeScript instead of JavaScript. This article does not cover the pros and cons of JavaScript. Rather than just focus on Good Parts of TypeScript.
Writing a command-line app is a challenge in many object-oriented languages. Most the object-oriented languages need heavy lifting structure(source code) to run a simple program. Java/Kotlin is one of them. Here, Gradle comes to save us.
Gradle is a framework helping us to create and maintain big applications. Gradle is awesome. However, setting up Gradle is also a tedious task. Here I will show step by step setup to build a scalable CLI(Command Line Interface) tool in Kotlin.
Create a folder and scaffold the structure with Gradle.
mkdir…
This is the first part of a series of articles that will help you to prepare for coding challenges. In this article, I will focus on the problems related to JavaScript strings.
Prerequisite: Before going forward, I am assuming you should have basic knowledge of JavaScript. At least you should know how it works.
Note: This is not a copy of Gayle_Laakmann’s book. The book is awesome. I love reading it whenever I get time. However, some samples/questions are taken from the book. While the book solves problems using Java, I have solved the same questions with JavaScript (TypeScript).
Strings…
express.js
code and want to create micro-services using Golang?Then this article is for you. This article will guide you step by step building block to build a scalable Golang project but in simple words.
Before going further you should ask this question to yourself and your teammates. Hope you are not migrating just for the sake that you want to try out something new. Golang is a new language but it is not that new. The first stable release was in 2009…
If you heard of Snowpack, you may be familiar with ESBuild. ESBuild is one of the fastest bundler/compilers for frontend libraries. ESBuild is written in Golang, which makes it fast. ESBuild is not a complete solution for your all needs. However, implementing it in your pipeline significantly can improve your team productivity and deployment build time.
Prerequisite:
Note: ESBuild is also available in nodejs. However, I find using Go and creating binary CLI is much faster and reusable.
There is no reason that you should stop using webpack. But there are a…
Performance testing or monitoring is not new to us. Whenever we create an API, We do need testing. For code and components, We write unit tests and integration tests. However, for performance, We need to load test and monitor the result.
I have worked on JMeter previously. It is a good tool. However, In this world of data. It is very hard to integrate JMeter with any programing language. I recently come across K6 when I was looking for Developer friendly load testing tool. K6 is in the open-source world for a long time. However, After writing a few load-testing…
There are a lot of tutorials to create Apollo Server and adding typing to it. However, creating a better project structure requires in-depth knowledge of Node.js and Apollo Server. Here in this article, I will explain the step-by-step process to build a robust and scalable server.
Before going further, I assume you have basic knowledge of Node.js and TypeScript. If you are new to Node.js, Please have a look at some basic tutorials on Node.js.
First, We need to create a project and init the configuration.
## Create a folder
mkdir apollo-server
cd apollo-server## Init npm package
npm init…
Creating a better UX is not as simple as it looks. Every component on-page matters. While working on a complex piece of code, we almost forgot about the simplest thing, a broken image.
Here in this tutorial, I will explain how you can create a simple Image
component without breaking existing code. This component will support lazy loading and broken images.
To start with, first create a folder in your component library and create a file named index.tsx
.
mkdir -p components/Image
touch components/Image/index.tsx
Add below line to index.tsx
.
// components/Image/index.tsx
import React from "react";interface ImageProps extends React.ImgHTMLAttributes<HTMLImageElement> {}export…
I am UI/UX lead developer, tech enthusiastic person. I am working in one of the biggest FinTech company, trying to solve basic challenges on ground issues.