Common JavaScript Interview Question

1.What Is JavaScript?

JavaScript is a programming language commonly used in web development. JavaScript is a client-side scripting language, which means the source code is processed by the client’s web browser rather than on the webserver. This means JavaScript functions can run after a webpage has loaded without communicating with the server.

Though Javascript is a client-side programming language it can run on the server with the help of node js. Not only that where node js can be installed javascript can run there. Node js is a runtime of Javascript. But it is made of C++.

2. DOM

DOM stands for Document Object Model. It represents the page so that programs can change the document structure, style, and content. The DOM represents the document as nodes and objects. That way, programming languages can connect to the page.

3. CallBack

A callback is a function passed as an argument to another function.

4.What do you understand by NaN?

NaN is a short form of Not a Number. Since NaN always compares unequal to any number, including NaN, it is usually used to indicate an error condition for a function that should return a valid number. When a string or something else is being converted into a number and cannot be done, we get to see NaN.

5.Explain the event loop in JavaScript?

The event loop is the secret behind JavaScript’s asynchronous programming. JS executes all operations on a single thread, but using a few smart data structures, gives us the illusion of multi-threading. Let’s take a look at what happens on the back-end.

The call stack is responsible for keeping track of all the operations in line to be executed. Whenever a function is finished, it is popped from the stack.

The event queue is responsible for sending new functions to the track for processing. It follows the queue data structure to maintain the correct sequence in which all operations should be sent for execution.

Whenever an async function is called, it is sent to a browser API. These are APIs built into the browser. Based on the command received from the call stack, the API starts its own single-threaded operation.

6.What are closures in JavaScript?

A closure is the combination of a function and the lexical environment within which that function was declared. i.e, It is an inner function that has access to the outer or enclosing function’s variables. The closure has three scope chains

  1. Own scope where variables defined between its curly brackets
  2. Outer function’s variables
  3. Global variables

Let’s take an example of the closure concept,

7.Scope in javascript?

In general terms, the scope will let us know at a given part of code, what are the variables and functions that we can or cannot access.

There are three types of scopes in JavaScript:

  • Global Scope
  • Local or Function Scope
  • Block Scope

8.Global Scope

Variables or functions declared in the global namespace have global scope, which means all the variables and functions having global scope can be accessed from anywhere inside the code

9.Function Scope

Any variables or functions declared inside a function have local/function scope, which means that all the variables and functions declared inside a function, can be accessed from within the function and not outside of it.

10.Block Scope

Block scope is related to the variables declared using let and const. Variables declared with var do not have block scope. Block scope tells us that any variable declared inside a block { }, can be accessed only inside that block and cannot be accessed outside of it.

11.Scope Chain

JavaScript engine also uses Scope to find variables. Let’s understand that using an example:

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

MobX for State Management

How to be too cool for PowerPoint

Angular — Typescript Abstract Classes

Constable

Social-media app

My Initial React(ion)

How To Run React With NodeJS Backend on GCP Cloud Run

Salesforce Compound Field

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
Tareq Hassan

Tareq Hassan

More from Medium

What is Reactjs Good for?

Best and Worst-Case Analysis of Linear Search and Binary Search Tree

React.js fundamental 10 concepts

My Marathon in Masai