[Go to site: main page, start]

0% found this document useful (0 votes)
3 views44 pages

JavaScript Interview Questions

jkjkj

Uploaded by

pp.23082004
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views44 pages

JavaScript Interview Questions

jkjkj

Uploaded by

pp.23082004
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ChatGPT Share

give most important questions for fresher interview in


Javascript with example

Here are the 20 most important JavaScript interview questions for freshers with simple
answers and examples. These topics are asked very frequently in interviews.
InterviewBit +1

1. What is JavaScript?
JavaScript is a scripting language used to make web pages interactive. It can run in
browsers and on servers using [Link]. MDN Web Docs +1

JavaScript

[Link]("Hello World");

2. Difference between var, let, and const


Feature var let const

Re-declare Yes No No

Reassign Yes Yes No

Scope Function Block Block

JavaScript

var a = 10;
let b = 20;
const c = 30;

3. Difference between == and ===


== checks value only.
=== checks value and datatype.

JavaScript

[Link](5 == "5"); // true


[Link](5 === "5"); // false

GeeksforGeeks +1

4. What are Data Types in JavaScript?


Primitive Types
String
Number
Boolean
Undefined
Null
Symbol
BigInt

JavaScript

let name = "Prashant";


let age = 22;
let isStudent = true;

InterviewBit

5. What is Hoisting?
Variables and functions are moved to the top of their scope before execution.

JavaScript

[Link](a);
var a = 10;

Output:

JavaScript
undefined

greatfrontend.c… +1

6. What is a Function?
A block of reusable code.

JavaScript

function greet() {
[Link]("Hello");
}

greet();

7. What is an Arrow Function?


Shorter syntax for writing functions.

JavaScript

const add = (a, b) => a + b;

[Link](add(2,3));

8. What is Scope?
Scope determines where variables can be accessed.

Types
Global Scope
Function Scope
Block Scope

JavaScript

let x = 10;

function test() {
let y = 20;
}

greatfrontend.c…

9. What is a Closure?
A function that remembers variables from its outer scope.

JavaScript

function outer() {
let count = 0;

return function() {
count++;
[Link](count);
};
}

const counter = outer();

counter(); //1
counter(); //2

InterviewBit +1

10. What is the DOM?


DOM stands for Document Object Model.

It allows JavaScript to access and modify HTML elements.

JavaScript

[Link]("demo").innerHTML = "Hello";

InterviewBit

11. What are Arrays?


Arrays store multiple values.
JavaScript

let fruits = ["Apple", "Banana", "Mango"];

[Link](fruits[0]);

12. Difference between map(), filter(), and reduce()


map()
Transforms data.

JavaScript

let nums = [1,2,3];

let result = [Link](n => n * 2);

[Link](result);

filter()
Filters data.

JavaScript

let result = [Link](n => n > 1);

reduce()
Produces a single value.

JavaScript

let sum = [Link]((a,b) => a+b,0);

[Link]

13. What is an Object?


Objects store data in key-value pairs.
JavaScript

let person = {
name: "Prashant",
age: 22
};

[Link]([Link]);

14. What is Destructuring?


Extract values from arrays or objects.

JavaScript

const person = {
name: "Prashant",
age: 22
};

const {name, age} = person;

[Link](name);

greatfrontend.c… +1

15. What is the Spread Operator (...)?


Used to copy or merge arrays and objects.

JavaScript

let arr1 = [1,2];


let arr2 = [...arr1,3,4];

[Link](arr2);

greatfrontend.c…

16. What is a Callback Function?


A function passed as an argument to another function.
JavaScript

function greet(name, callback) {


[Link](name);
callback();
}

greet("Prashant", () => {
[Link]("Welcome");
});

[Link] +1

17. What is a Promise?


Used to handle asynchronous operations.

States:
Pending
Fulfilled
Rejected

JavaScript

let promise = new Promise((resolve, reject) => {


resolve("Success");
});

[Link](data => [Link](data));

Medium +1

18. What is Async/Await?


Cleaner way to work with Promises.

JavaScript

async function getData() {


return "Hello";
}

getData().then([Link]);
igmguru +1

19. What is the Event Loop?


JavaScript is single-threaded. The Event Loop handles asynchronous tasks and executes
them when the call stack becomes empty. igmguru +1

Example:

JavaScript

[Link]("Start");

setTimeout(() => {
[Link]("Timer");
}, 0);

[Link]("End");

Output:

JavaScript

Start
End
Timer

20. What is this Keyword?


this refers to the object that calls the function.

JavaScript

const person = {
name: "Prashant",

greet() {
[Link]([Link]);
}
};

[Link]();
greatfrontend.c…

Coding Questions Frequently Asked


1. Reverse a String
2. Check Palindrome
3. Find Largest Number in Array
4. Remove Duplicates from Array
5. Count Vowels
6. Fibonacci Series
7. Factorial Program
8. Prime Number Check
9. Sort an Array
10. Find Missing Number

These are among the most common fresher coding questions. [Link] +1

For MERN/Frontend interviews, focus especially on:

var vs let vs const


== vs ===
Hoisting
Closures
Scope
Callbacks
Promises
Async/Await
Event Loop
DOM Manipulation

These 10 topics alone cover a large percentage of fresher JavaScript interviews.


InterviewBit +2

Sources

give most important questions for fresher interview in


react with example
If you're preparing for a React Developer Fresher Interview, focus on these 15 most
important questions. These are asked in almost every React interview. InterviewBit +1

1. What is React?
React is a JavaScript library used to build user interfaces using reusable components. React
applications are built from components that can be combined to create complete pages.
React +1

Example

function App() {
return <h1>Hello React</h1>;
}

J S i t

2. What is JSX?
JSX (JavaScript XML) allows us to write HTML-like code inside JavaScript. React converts
JSX into JavaScript behind the scenes. [Link] +1

Example

const element = <h1>Welcome</h1>;


JavaScript

3. What is a Component?
A component is a reusable piece of UI.

Example

function Welcome() {
return <h2>Welcome User</h2>;
}

J S i t

Types
Functional Component
Class Component

InterviewBit +1

4. What are Props?


Props are used to pass data from a parent component to a child component.

Example

function Student(props) {
return <h2>{[Link]}</h2>;
}

<Student name="Prashant" />

InterviewBit +1

5. What is State?
State stores data that can change during the component's lifecycle.

Example

import { useState } from "react";

function Counter() {
const [count, setCount] = useState(0);

return (
<>
<h2>{count}</h2>
<button => setCount(count + 1)}>
Increment
</button>
</>
);
}
InterviewBit +1

6. Difference Between Props and State


Props State

Passed from parent Managed inside component

Read-only Can be updated

External data Internal data

Medium +1

7. What is Virtual DOM?


Virtual DOM is a lightweight copy of the real DOM. When data changes, React updates the
Virtual DOM first, compares it with the previous version (diffing), and updates only the
necessary parts of the real DOM. GeeksforGeeks +1

Interview Answer

Virtual DOM improves performance by minimizing direct DOM manipulations.

8. What is useState Hook?


useState allows functional components to manage state.

Example

const [name, setName] = useState("Prashant");


JavaScript

InterviewBit +1

9. What is useEffect Hook?


useEffect is used for side effects such as API calls, timers, and DOM updates.
InterviewBit +1

Example

import { useEffect } from "react";

useEffect(() => {
[Link]("Component Loaded");
}, []);

10. What are Keys in React?


Keys help React identify which items have changed in a list.

Example

const fruits = ["Apple", "Mango"];

[Link]((fruit, index) => (


<li key={index}>{fruit}</li>
));

InterviewBit +1

11. Controlled vs Uncontrolled Components


Controlled Component
React controls the form data.

const [name, setName] = useState("");

<input
value={name}
=> setName([Link])}
/>
Uncontrolled Component
DOM controls the form data using refs.

[Link] +1

12. What is Conditional Rendering?


Displaying UI based on conditions.

Example

function App() {
const isLoggedIn = true;

return (
<>
{isLoggedIn ? <h1>Welcome</h1> : <h1>Please Login</h1>}
</>
);
}

InterviewBit +1

13. What is React Router?


React Router enables navigation between pages without refreshing the browser.
InterviewBit +1

Example

<Route path="/about" element={<About />} />


JavaScript

14. What is Context API?


Context API allows sharing data between components without passing props manually
through many levels (prop drilling). InterviewBit +1

Example

const UserContext = createContext();


JavaScript

15. What is Prop Drilling?


Passing props through multiple components just to reach a deeply nested component.

Solution:
Context API
Redux

[Link] +1

Coding Questions Frequently Asked


1. Counter App

const [count, setCount] = useState(0);


JavaScript

2. Toggle Button

const [show, setShow] = useState(false);


JavaScript

3. Fetch API Data

useEffect(() => {
fetch("[Link]
.then(res => [Link]())
.then(data => [Link](data));
}, []);
JavaScript

4. Search Filter

const filtered = [Link](user =>


[Link]().includes([Link]())
);

J S i t

5. Todo App
Add Todo
Delete Todo
Mark Complete

Top 10 React Topics You Must Master


1. JSX
2. Components
3. Props
4. State
5. useState
6. useEffect
7. Virtual DOM
8. Event Handling
9. Context API
10. React Router

These topics cover the majority of React fresher interview questions. NareshIT +1

Since you're interested in MERN development, the next step would be learning:
React Hooks → Context API → React Router → API Integration (Axios/Fetch) → Redux →
Project Building.

Sources

give most important questions for fresher interview in


node with example
Top 20 [Link] Interview Questions for Freshers (with
Examples)
[Link] is a JavaScript runtime built on Google's V8 engine that allows JavaScript to run on
the server side. It uses an event-driven, non-blocking I/O model, making it suitable for
scalable applications. Wikipedia +1

1. What is [Link]?
[Link] is a runtime environment that executes JavaScript outside the browser.

Example

[Link]("Hello [Link]");
JavaScript

2. What are the advantages of [Link]?


Fast execution using V8 Engine
Non-blocking I/O
Event-driven architecture
Single language (JavaScript) for frontend and backend
Scalable applications

Wikipedia +1

3. What is NPM?
NPM (Node Package Manager) is used to install and manage packages.

Commands

npm init
npm install express

B h
npm Bash
install mongoose

4. What is the Event Loop?


The Event Loop handles asynchronous operations without blocking the main thread. It
processes callbacks and queued tasks after synchronous code finishes. [Link] +1

Example

[Link]("Start");

setTimeout(() => {
[Link]("Timer");
}, 0);

[Link]("End");

Output:

Start
End
Timer

J S i t

5. What is Non-Blocking I/O?


[Link] can continue executing other tasks while waiting for I/O operations like file
reading or database queries. GeeksforGeeks +1

Example

const fs = require("fs");

[Link]("[Link]", "utf8", (err, data) => {


[Link](data);
});
[Link]("Reading file...");
JavaScript

6. What is a Module in [Link]?


A module is a reusable piece of code.

[Link]

[Link] = (a, b) => a + b;


JavaScript

[Link]

const math = require("./math");

[Link]([Link](5, 3));

J S i t

7. What is require()?
require() is used to import modules.

const fs = require("fs");
JavaScript

8. Difference Between CommonJS and ES Modules


CommonJS

const express = require("express");


JavaScript

ES Module
import express from "express";
JavaScript

9. What is [Link]?
It contains project information, dependencies, scripts, and version details.

Example:

{
"name": "myapp",
"version": "1.0.0"
}

10. What is [Link]?


[Link] is a [Link] framework used for building APIs and web applications.

Example

const express = require("express");

const app = express();

[Link]("/", (req, res) => {


[Link]("Hello Express");
});

[Link](3000);

11. What is Middleware?


Middleware functions execute before the request reaches the route handler.

Example
[Link]((req, res, next) => {
[Link]("Request received");
next();
});

12. What are Callbacks?


Callbacks are functions passed as arguments and executed later.

function greet(name, callback) {


[Link]("Hello " + name);
callback();
}

greet("Prashant", () => {
[Link]("Welcome");
});

13. What are Promises?


Promises handle asynchronous operations more cleanly than callbacks. [Link]

const promise = new Promise((resolve) => {


resolve("Success");
});

[Link](data => [Link](data));

14. What is Async/Await?


Async/Await simplifies working with promises. [Link]
async function getData() {
return "[Link]";
}

getData().then([Link]);
JavaScript

15. What is a Stream?


Streams process data piece by piece instead of loading everything into memory.

Example

const fs = require("fs");

const stream = [Link]("[Link]");

[Link]("data", chunk => {


[Link]([Link]());
});

16. What is Buffer?


A Buffer stores binary data temporarily.

const buffer = [Link]("Hello");

[Link](buffer);

J S i t

17. What is REST API?


REST API allows communication between client and server using HTTP methods.

Methods
GET
POST
PUT
DELETE

Example:

[Link]("/users", (req, res) => {


[Link]("All Users");
});

J S i t

18. How do you handle Errors in [Link]?


Callback Error Handling

[Link]("[Link]", (err, data) => {


if (err) {
[Link](err);
return;
}
});

Try-Catch

try {
[Link]("Success");
} catch (error) {
[Link](error);
}

19. What is MongoDB's Role in [Link] Applications?


MongoDB is commonly used as a NoSQL database with [Link].

Mongoose Example
const mongoose = require("mongoose");

JavaScript
[Link]("mongodb://localhost:27017/test");

20. What is the Difference Between [Link] and


JavaScript?
JavaScript [Link]

Runs in browser Runs on server

DOM available DOM not available

Frontend development Backend development

Wikipedia

Most Frequently Asked Coding Questions


Reverse String

function reverse(str) {
return [Link]("").reverse().join("");
}

J S i t

Check Palindrome

function palindrome(str) {
return str === [Link]("").reverse().join("");
}

J S i t

Find Largest Number

const arr = [10, 20, 5, 40];


[Link]([Link](...arr));

J S i t

Remove Duplicates

const arr = [1, 2, 2, 3];

[Link]([...new Set(arr)]);

J S i t

Count Vowels

function countVowels(str) {
return [Link](/[aeiou]/gi)?.length || 0;
}

J S i t

Top 10 [Link] Topics for Freshers


1. [Link] Architecture
2. Event Loop
3. Modules
4. NPM
5. [Link]
6. Middleware
7. REST APIs
8. Callbacks
9. Promises & Async/Await
10. MongoDB + Mongoose

For MERN Stack interviews, interviewers often focus on:


Event Loop
Async/Await
Express Middleware
REST APIs
JWT Authentication
MongoDB Integration
Error Handling
File Uploads
CRUD Operations
Authentication & Authorization

Master these topics and you'll be prepared for most [Link] fresher interviews.

Sources

give most important questions for fresher interview in


mongoDB with example

Top 20 MongoDB Interview Questions for Freshers (with


Examples)
MongoDB is a NoSQL document-oriented database that stores data in BSON (JSON-like)
documents instead of rows and tables. It is known for flexibility, scalability, and high
performance. [Link] +1

1. What is MongoDB?
MongoDB is a NoSQL database that stores data in collections and documents rather than
tables and rows. igmguru +1

Example Document

{
"name": "Prashant",
"age": 22,
"skills": ["React", "[Link]", "MongoDB"]
}

2. What is the Difference Between SQL and MongoDB?


SQL MongoDB

Tables Collections
SQL MongoDB

Rows Documents

Fixed Schema Flexible Schema

JOINs $lookup

MySQL, PostgreSQL MongoDB

igmguru +1

3. What is a Collection?
A collection is a group of MongoDB documents.

[Link]("students")
JavaScript

4. What is a Document?
A document is a record stored in MongoDB.

{
"_id": 1,
"name": "Prashant",
"city": "Delhi"
}

5. What is BSON?
BSON stands for Binary JSON. MongoDB stores data internally in BSON format.
[Link]

CRUD Operations (Most Important)


6. How do you Insert Data?

insertOne()

[Link]({
name: "Prashant",
age: 22
})

insertMany()

[Link]([
{name: "Aman"},
{name: "Rohit"}
])

GeeksforGeeks

7. How do you Read Data?

find()

[Link]()
JavaScript

findOne()

[Link]({name: "Prashant"})
JavaScript

GeeksforGeeks

8. How do you Update Data?


[Link](
{name: "Prashant"},
{$set: {age: 23}}
)

GeeksforGeeks

9. How do you Delete Data?

[Link]({
name: "Prashant"
})

J S i t
GeeksforGeeks

10. What are Query Operators?

Greater Than

[Link]({
age: {$gt: 20}
})

J S i t

Less Than

[Link]({
age: {$lt: 25}
})

J S i t
GeeksforGeeks

Frequently Asked Intermediate Questions


11. What is Indexing?
Indexes improve query performance by helping MongoDB find data faster. However, they
use extra storage. Sanfoundry +1

Example

[Link]({
email: 1
})

J S i t
DataCamp

12. What is Aggregation?


Aggregation processes data through multiple stages to generate summarized results.
GeeksforGeeks +1

Example

[Link]([
{
$group: {
_id: "$status",
total: {$sum: "$amount"}
}
}
])

13. What is $match?


Used to filter documents.

[Link]([
{
$match: {
status: "completed"
}
}
])
JavaScript

DataCamp +1

14. What is $group?


Used to group documents and perform calculations.

[Link]([
{
$group: {
_id: "$city",
count: {$sum: 1}
}
}
])

Medium

15. What is $lookup?


MongoDB's equivalent of SQL JOIN. DataCamp +1

Example

[Link]([
{
$lookup: {
from: "customers",
localField: "customerId",
foreignField: "_id",
as: "customerInfo"
}
}
])

16. What is Replication?


Replication creates multiple copies of data for high availability using Replica Sets. If the
primary server fails, another server can become primary. Wikipedia +1

17. What is Sharding?


Sharding distributes data across multiple servers to handle large datasets and increase
scalability. LinkedIn +1

18. What is a Replica Set?


A group of MongoDB servers that maintain the same data for fault tolerance and
availability. Coursesity

19. What are MongoDB Backup Tools?


Common backup and restore utilities:
mongodump
mongorestore
mongoimport
mongoexport

InterviewBit +1

20. How Do You Optimize a Slow Query?

Common Techniques
Create indexes
Use projections
Avoid unnecessary fields
Use aggregation efficiently
Analyze queries using explain()

InterviewBit +1

MongoDB Coding Questions Asked in Interviews


Find All Students

[Link]()
JavaScript

Find Students Age > 20

[Link]({
age: {$gt: 20}
})

J S i t

Update Student

[Link](
{name: "Prashant"},
{$set: {city: "Noida"}}
)

Delete Student

[Link]({
name: "Prashant"
})

J S i t

Count Documents

[Link]()
JavaScript

Top 10 MongoDB Topics for MERN Interviews


1. Collections & Documents
2. CRUD Operations
3. Query Operators
4. Indexing
5. Aggregation Pipeline
6. $match
7. $group
8. $lookup
9. Replication
10. Sharding

For MERN Stack fresher interviews, interviewers most often ask:


What is MongoDB?
SQL vs MongoDB
CRUD Operations
Indexing
Aggregation
$lookup
Replication
Sharding
Mongoose
Schema vs Model

Master these topics along with React and [Link], and you'll be well-prepared for most
MERN fresher interviews.

Sources

give most important questions for fresher interview in


Expressjs with example

Top 20 [Link] Interview Questions for Freshers (with


Examples)
[Link] is a lightweight web framework for [Link] used to build web applications and
REST APIs quickly. It provides routing, middleware support, and HTTP utilities.

1. What is [Link]?
[Link] is a [Link] framework that simplifies server-side development.
Example

JavaScript

const express = require("express");


const app = express();

[Link](3000, () => {
[Link]("Server Running");
});

2. Why Use [Link]?


Advantages
Fast development
Easy routing
Middleware support
REST API development
Scalable applications

3. How to Install Express?

Bash

npm init -y
npm install express

4. What is Routing in Express?


Routing determines how the application responds to client requests.

Example

JavaScript

[Link]("/", (req, res) => {


[Link]("Home Page");
});
5. What are HTTP Methods?
Method Purpose

GET Fetch data

POST Create data

PUT Update data

DELETE Remove data

Example

JavaScript

[Link]("/users", (req, res) => {


[Link]("User Created");
});

6. What is Middleware?
Middleware functions execute between receiving a request and sending a response.

Example

JavaScript

[Link]((req, res, next) => {


[Link]("Request Received");
next();
});

Interview Answer

Middleware is used for authentication, logging, validation, and error handling.

7. What is [Link]()?
[Link]() registers middleware.
JavaScript

[Link]([Link]());

This middleware converts JSON request data into JavaScript objects.

8. What is req Object?


req contains information about the incoming request.

Example

JavaScript

[Link]("/", (req, res) => {


[Link]([Link]);
[Link]("Hello");
});

9. What is res Object?


res is used to send responses to the client.

Example

JavaScript

[Link]("Success");

Other methods:

JavaScript

[Link]()
[Link]()
[Link]()

10. Difference Between [Link]() and [Link]()


send()
JavaScript

[Link]("Hello");

json()

JavaScript

[Link]({
name: "Prashant"
});

[Link]() automatically sends JSON format.

11. What is [Link]()?


Used to parse JSON data from request body.

Example

JavaScript

[Link]([Link]());

Without it:

JavaScript

[Link]

will be undefined.

12. How to Access URL Parameters?


Route Parameter

JavaScript

[Link]("/user/:id", (req, res) => {


[Link]([Link]);
});
URL:

/user/101

Output:

101

13. How to Access Query Parameters?


Example

JavaScript

[Link]("/search", (req, res) => {


[Link]([Link]);
});

URL:

/search?name=Prashant

Output:

Prashant

14. What is Express Router?


Used to organize routes into separate files.

[Link]

JavaScript

const router = require("express").Router();

[Link]("/", (req, res) => {


[Link]("Users");
});
[Link] = router;

[Link]

JavaScript

[Link]("/users", userRoutes);

15. What is Error Handling Middleware?


Used to handle application errors.

Example

JavaScript

[Link]((err, req, res, next) => {


[Link](500).send("Server Error");
});

16. What is REST API?


REST API allows communication between client and server using HTTP methods.

Example

JavaScript

[Link]("/products", (req, res) => {


[Link](products);
});

17. What is CORS?


CORS (Cross-Origin Resource Sharing) allows frontend and backend on different domains
to communicate.

Install
Bash

npm install cors

Example

JavaScript

const cors = require("cors");

[Link](cors());

18. How to Serve Static Files?


Example

JavaScript

[Link]([Link]("public"));

Folder Structure:

public/
[Link]
[Link]

19. What is Authentication Middleware?


Middleware that verifies users before allowing access.

Example

JavaScript

function auth(req, res, next) {


if (true) {
next();
} else {
[Link]("Unauthorized");
}
}
[Link]("/profile", auth, (req, res) => {
[Link]("Profile");
});

20. What is the Difference Between [Link] and [Link]?


[Link] [Link]

Runtime Environment Framework

Runs JavaScript Builds APIs

Low-level High-level

More code Less code

Most Asked [Link] Coding Questions


1. Create a Simple Server

JavaScript

const express = require("express");


const app = express();

[Link](3000);

2. Create GET Route

JavaScript

[Link]("/", (req, res) => {


[Link]("Hello Express");
});

3. Create POST Route


JavaScript

[Link]("/users", (req, res) => {


[Link]("User Added");
});

4. Create Middleware

JavaScript

[Link]((req, res, next) => {


[Link]("Middleware");
next();
});

5. Create CRUD API

JavaScript

[Link]("/users", getUsers);

[Link]("/users", createUser);

[Link]("/users/:id", updateUser);

[Link]("/users/:id", deleteUser);

Top 10 [Link] Topics for MERN Interviews


1. Express Basics
2. Routing
3. Middleware
4. Express Router
5. Request & Response Objects
6. Route Parameters
7. Query Parameters
8. REST APIs
9. Error Handling
10. Authentication Middleware

Most Frequently Asked in MERN Interviews


What is [Link]?
What is Middleware?
Difference between [Link]() and [Link]()
What is Express Router?
How does [Link] work?
How does [Link] work?
How to create a REST API?
What is CORS?
How to handle errors?
How to implement authentication middleware?

If you're preparing for a MERN Stack Fresher Interview, focus heavily on:
JavaScript → React → [Link] → [Link] → MongoDB → REST APIs → JWT
Authentication → CRUD Operations, because these topics appear in most fresher
interviews.

Sources

You might also like