10 Intermediate JavaScript Concepts (helpful for interview).

Sagar Biswas
4 min readMay 8, 2021

Being a complex language JavaScript has some fundamental concepts. As a developer, we need to have a good understanding over these topics. Here 10 concepts are explained briefly to give a simple understanding of intermediate JavaScript.

1. What is Closure?

A simple answer can be, when we return a function from the parent function, it creates a closed environment and keeps a copy of the variables it accesses from the global scope or from the local scope of its parent. So it can maintain all the references that are used separately for all of its use cases. Just see the following example:

Here counter1 and counter2 have created a closed environment for themselves separately. So it does not matter when and in which sequence we call them, they are maintained separately in the closed environment and gives a sequential increment of the number for each of them on each call.

2. What is the difference between double equal and triple equal?

The answer is simple. while double equal compares between values, triple equal compares between type and value together. but double equal is a little bit interesting. it actually tries to compare the values ignoring their types. that’s why (2==”2") will be true. but what if we put (1==true). See the following example

3. How setTimeout, setInterval work?

As the name depicts setTimeout is asynchronous and executes a certain block of codes once after the specified time stated in it.
And setInterval executes a certain block of codes at a regular interval at a fixed time delay stated in it.

but there is a little bit to say about setTimeout. It does not necessarily mean that it will be executed at the exact time given to it. rather it ensures the execution will be started after the given time.

let myName = setTimeout(function () {
console.log(“Hello, I’m Sam”);
}, 0);

console.log(myName);
console.log(“hi user”);

Here you will notice that the outputs are-
“hi user”
“Hello, I’m Sam”

4. What’s the difference between Null & Undefined?

There are some differences between them. Null means there is nothing that is explicitly assigned to a variable. The interesting fact is that the type of null is an object.
Undefined means the value of a variable is not defined or found. Undefined can be generated in several ways

5. What is DOM?

DOM stands for document object model. DOM basically provides us some APIs using which we can modify the html/css with the help of JavaScript which is also known as DOM manipulation. Without DOM we cant access and update the content, structure, and style of a document. The browser converts the file into a tree-like data structure and lets JavaScript play with it.

6. What is an API?

API stands for Application Programming Interface. API lets us interact with different systems. API is something that helps you to maintain seamless connectivity with the system. For example, It can be considered as a waiter of a restaurant. you are giving some orders to him. he goes to the kitchen and comes back with the processed order. Then it’s up to you how you are consuming the delivery.

7. Differences between GET and POST method:

The (HTTP) Hypertext Transfer Protocol is there for communicating between clients and servers. Get and Post are two of its several methods.
GET is one of the most used common HTTP methods so that we can request data from a specified resource. Some characteristics are: can be cached, remain in the browser history, can be bookmarked, only used to request data.

POST is used for the purpose of sending data to a server to create/update a resource. Some characteristics are: can’t be cached, don’t remain in the browser history, can’t be bookmarked, have no restrictions on data length.

8. What is asynchronous in JavaScript?

JavaScript is Known as a single-threaded programming language. This means it can only perform one thing at a time in a single thread. But when you have a lot of code to execute and some of them calling some APIs from the server. Obviously requesting data from APIs will take some time. If the browser just waits for getting the results then it will block the remaining thread to further processing leading to disruption in performance and user experience. in this case, asynchronous JavaScript plays a good role. We can perform long network requests and it will not block the main thread.

9. How Does Asynchronous JavaScript Work?

It’s an interesting fact to explore. There is an execution context. It can be considered as an environment where the code is evaluated and executed. Codes running in JavaScript mean they are running inside an execution context.

Here there is a combination of Call Stack-> Web APIs->Message Queue-> Event Loop.

Call stack performs according to the LIFO principle. when a code is encountered it is pushed to the top of the stack and when finished it is popped off the stack. when there is an asynchronous function then it is moved to the web API environment. From here it is queued in message Queue which follows the FIFO principle. Here event loop plays its role.it tracks the call stack and determines whether the call stack is empty or not.it also tracks the message queue. if the stack is empty and it finds any callback to be executed in the queue then the code is pushed to the stack for final execution.

10 . What are truthy and falsy values and “new” keyword in JavaScript?

The falsy values contains boolean false, empty string“”,0,undefined,null,NaN .
Unlike the values stated above rest of the values can be considered as truthy.

Sometimes we make an object template using the class constructor. Again there are some build-in object types in JavaScript that have a constructor function. The new Operator lets us create a new object from a user-defined object type or built-in object types having a constructor function available in JavaScript.

--

--