Image for post
Image for post

It is a concept for implementing lexical scope binding in javascript by using functions. Closure is created when inner functions are able to access the variables of outer function. What closure does is it remembers the state of the function, even after the function as returned. If we have to create a closure, we have to define a function inside another function and return so, that inner function will be having access to outer function variables.

Lexical environment is a reference to the outer functions scope and is part of the every function execution context.

Unlike a normal function, closure allows the function to access the stored variables through closures copy of their references even when it is called outside the function. As every function will be having a reference to its lexical environment that's how it sees and can access variables declared outside the function. …


Image for post
Image for post

One of the most weird concepts of javascript is where this keyword is referencing to. Every function receives two addition parameters excluding declared parameter: this and arguments. The this keyword is very important in javascript and let's see what it is.

Every function while executing has a reference to its current execution context called “ this". Here execution refers to where the function is getting called and when it will be called. There are four rules for how "this" keyword gets bind. It tells how "this" keyword will get bind for functions. Let's see what are those.

1. Function Binding

Let's take an example and see how “this” gets bind. …


Hoisting in JavaScript and why we need
Hoisting in JavaScript and why we need
Photo by Bharat Patil on Unsplash

In my last post, we have discussed all about scope. When we started looking in-depth we thought like how come var doesn’t through error even if its undeclared. So we are going to discuss about hoisting and what actually it is happening.

Hoisting variables

So let’s take a simple example (here compilation phase means after hoisting)

Image for post
Image for post

In image 1 what it happens is first it will do a run through the code and defines a and b. Meant first the compilation of variables and function expressions will happen from lines 1–6 before execution. After that we can see from image 2(compilation phase), variable declaration of a and b has moved to the top of the scope. This is called hoisting or hoisting the variables and functions to the top of the scope. …


Scope, Hoisting, and this Keyword In JavaScript
Scope, Hoisting, and this Keyword In JavaScript
Photo by Greg Rakozy on Unsplash

It means “where to look for things?”. What we are looking for means we are looking for variables, what variables we have access to. There are two kinds of javascript scope i.e global and local.

Global Scope

A variable declared outside a function becomes global. All functions have access to global variables. Declarations, where they are occurred will be processed before any code execution is done and there initial value is. This is called as and we will discuss that as well.

Local Scope

Variables that are available only in a specific part of our code are considered to be in the local scope. …


Javascript Map, WeakMap and Set
Javascript Map, WeakMap and Set

In this post, you will learn about JavaScript Map, WeakMap, Set related interview questions you may face, and few exercises.

Maps

Map uses key value pairs and keeps the original insertion order of the keys. Any value may be used as key.

Properties and Methods of Map (only Size is property)

  • Size — We can get the size of the maps
  • Clear — We can clear out the map completely
  • Delete — Can delete specific items of the map
  • Entries — Can get the entries of the map
  • forEach — For iterating through them
  • Get — Can get the value based on…

About

Vinay Kumar

Writing code with JavaScript

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