A guide that will take you from a promise novice to ninja.

Image for post
Image for post

What is Promise?

Promise represents the result of an asynchronous operation. You can think of it as a placeholder for a result that you’ll eventually receive.

Why Promise?

To solve the problem of callback hell.

Callback hell is any code where the use of function callbacks in asynchronous code becomes difficult to follow. Whenever we have loads of nested callbacks, code becomes harder to read, test, and debug. This also leads to the pyramid of doom.

Here is an example of callback hell.

Three states of Promise

Image for post
Image for post
Three States of Promise

Pending → Before the result is ready, a promise is in a pending state.

Fulfilled → If the result is available it becomes…

setTimeout() can yield unexpected results if you don’t understand how it works under the hood. Let’s learn about it and become setTimeout() ninja.

Image for post
Image for post


It is a function in JavaScript that delays the execution of code.

Parts of setTimeout():

Image for post
Image for post
Parts of setTimeout()

SetTimeout has 3 parts:

  • Callback
  • Statements to be executed inside of a callback
  • Time in milliseconds (delay time)

The above code prints “Hello” and “Bye” in the terminal after 1 second (1000ms = 1s).

Seems easy right! But if we don’t know how setTimeout() behaves under the hood we might get some unexpected behavior.

Example 1: Single setTimeout()

Output:Sum = 3
1 2

Explanation: In the above example setTimeout() has a delay of 1 second. …

When you read you begin with ABC, when you sing you begin with Do-Re-Mi, when you start an array it begins with 0 1 2 3.

Image for post
Image for post
source: imgur

If you are using high level languages like Java, Python, or JavaScript, it might not be easy to understand how arrays work under the hood because these languages abstract away a lot of complexity. One of which is why the 1st element in an array is at index 0 and not at 1.

To understand let’s look at how arrays work in C.

To initialize an array:

int a[5] = {1,2,3,4,5};

Now we have an array of 5 empty elements of type integer from index 0 to 4.

Image for post
Image for post

When we run a program, a piece of memory is allocated by the OS . Let’s say our program has more logic than just an array and the allotted memory is 64KB. …

The bare minimum that every developer needs to know. 👨🏽‍💻

Image for post
Image for post
UTF — Created By Piyush Kochhar

What Is Unicode❓

A Unicode is a set of standards for representing characters. It’s just one huge list of characters that contain standards for international languages, emoji’s, glyphs etc. It even contains standards for the characters that don’t exist yet. Each character is represented by ‘U+xxxx” in hexadecimal (don’t worry it’ll make sense later). There are many encodings available for representing characters, but we’ll limit to scope to ASCII and UTF (Unicode Transformation Format) encodings like UTF-8, UTF-16 and UTF-32.

Before we dive into ASCII & UTF let’s look at some terms that we need to understand these concepts.

Remember that everything that we see on our devices ultimately translates into binary code. Similarly, characters are encoded into binary using different character encodings. …

Yes, you read it right! There are more ways than one to swap values in JavaScript

Image for post
Image for post
Photo by Max Duzij on Unsplash

At some point in their career, developers need to swap values. Most of the time we use the one plain old solution of “using a temporary variable”. Ugh, if only there was a better way. But wait! There is, and there’s not just one but many. In desperate times, we scour the web for solutions, find one, and copy it without ever wondering how this little snippet of code works. Lucky for you, now is the time to learn about how to swap values easily and efficiently, putting an end to your misery.

1) Using a temporary variable

Let’s just get the most obvious one out of the way. …

A simple guide to understand HTML Meta tag

Image for post
Image for post
You don’t know meta— Created By Piyush Kochhar

Meta tags are used for the metadata of the webpage. These tags are inside in the head tag and don’t really have any visual impact but are crucial for search engine optimization (SEO). These tags are read by web crawlers or browsers.

When building a webpage, we have numerous metadata options available for defining the information about the webpage. In addition to essential information such as the page title, page description, and charset definition, the <head> can provide comprehensive information for browsers. …

Pipes and filters are everywhere. Not just in your homes but also in the terminal.

Image for post
Image for post
Know your pipes and filters — Created by Piyush Kochhar

What is a Filter? ䷜

A filter takes input from one command, does some processing, and gives output.

Why filter data? 🗂

Filtering is useful when you want to extract specific information from large amounts of data. It doesn’t remove or modify any data; it just displays a subset of data on the screen. Sometimes we use pipes to filter complex data.

What is a Pipe? 🚰

The symbol ‘|’ denotes a pipe. It is a command that takes an output of one command and feeds it as an input to the second command. You can combine two or more commands and run them consecutively with pipes.


$ command 1 | command 2 |… command…

A friendly guide to soft and hard links.

Image for post
Image for post
Soft Links & Hard Links — Created by Piyush Kochhar

What are Links?

A link in an operating system is a pointer to a file. If you’ve ever worked with programming languages like C, ++ etc., you’ve probably programmed using pointers which are nothing but pointers to other files and directories. Operating systems like Windows, have concepts of shortcuts which at the end are nothing but a type of link.

The two kinds of links:

  • Soft Links or Symbolic Links
  • Hard Links

Before we look into links, let’s learn about inodes.


Inode is an entry in an inode table. It contains metadata about the file.

An inode structure looks something like:

Image for post
Image for post
Inode Structure

This structure contains information like file permissions, the owner or group of owners of the file, the locations size in bytes and inode creation, modification time etc. …

A quick introduction to encoding, decoding, encryption, decryption and hashing.

Image for post
Image for post
Introduction to Encoding, Decoding, Encryption, Decryption & Hashing — Created by Piyush Kochhar


Encoding is a process of conversion of data from one format to another. It includes the utilization of a code to change unique information into a structure that can be utilized by an external application.

The code utilized for changing over characters is called American Standard Code for Information Interchange (ASCII), the most commonly utilized encoding for files that contain text.

Media files such as audio and video use encoding to reduce their file size. Each audio and video file format has a corresponding coder-decoder (codec) program that is used to code it into the appropriate format and then decodes for playback. For example, converting .mp4 into .avi, .flv to .mp3 etc. …

A missing guide on ROT13 that will make you an expert.

Image for post
Image for post
ROT13: A Missing Guide — Created by Piyush Kochhar

ROT13 (Rotate by 13 places) is an encoding technique and is a subset of Caesar cipher.

What does it do?

ROT13 encodes each character of a string into its equivalent 13th character.

E.g. ROT13 for Piyush => Cvlhfu


13th character from letter ‘a’ => ’n’, therefore ‘a’ maps to ‘n’

13th character from letter ‘z’ => ‘m’, therefore ‘z’ maps to ‘m’

Before we find an algorithm for ROT13. Let’s quickly see what tr command is.

tr means translate. It substitutes the characters with the characters of your choice.

$ echo hello | tr h m
Image for post
Image for post
Here we have substituted letter ‘h’ in hello with ‘m’
$ echo hello | tr ho jy
Image for post
Image for post

We get this result because each character as 1st argument to tr will map to its corresponding character in the 2nd argument to…


Piyush Kochhar

JavaScript | React | Node | MongoDB

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store