Basic Concepts
What is JavaScript, and how is it different from Java?
- JavaScript is a lightweight, interpreted programming language used primarily for web development. It is different from Java, which is a statically typed, compiled language used for a broader range of applications.
Explain the difference between var
, let
, and const
.
var
has function scope and can be redeclared and updated.let
has block scope and can be updated but not redeclared.const
also has block scope and cannot be updated or redeclared.

What are the data types in JavaScript?
- Primitive types:
undefined
,null
,boolean
,number
,string
,symbol
,bigint
- Non-primitive types:
object
What is a closure in JavaScript?
- A closure is a function that retains access to its lexical scope, even when the function is executed outside that scope.
Table Of Contents
Explain this
keyword in JavaScript.
this
refers to the object from which the function was called. Its value depends on the context in which the function is executed.
Intermediate Concepts
What is event delegation?
- Event delegation is a technique of using a single event listener to manage all events of a particular type on child elements by taking advantage of event bubbling.
Explain the concept of promises in JavaScript.
- A promise is an object representing the eventual completion or failure of an asynchronous operation. It allows chaining operations with
.then()
and handling errors with.catch()
.
What is the difference between ==
and ===
?
==
compares values for equality, performing type coercion if necessary.===
compares both values and types for strict equality.
What is hoisting in JavaScript?
- Hoisting is a behavior where variable and function declarations are moved to the top of their containing scope during the compile phase.
JavaScript Beginner to Advanced All Topics
What are arrow functions, and how do they differ from regular functions?
Arrow functions are a shorthand for writing function expressions. They do not have their own this
context and cannot be used as constructors.
Advanced Concepts
- Explain the concept of async/await.
async/await
is syntax for handling asynchronous operations more efficiently.async
functions return a promise, andawait
pauses the execution of anasync
function until the promise is resolved.
- What is the event loop in JavaScript?
- The event loop is a mechanism that handles the execution of multiple chunks of your program, such as callbacks from promises and events. It ensures that functions are executed in the order they are called.
- How does prototypal inheritance work in JavaScript?
- In JavaScript, objects can inherit properties and methods from other objects via the prototype chain. Each object has a private property that references its prototype.
- What are modules in JavaScript, and how do you use them?
- Modules are reusable pieces of code that can be imported and exported between different parts of a JavaScript application. ES6 introduced the
import
andexport
syntax for this purpose.
- Modules are reusable pieces of code that can be imported and exported between different parts of a JavaScript application. ES6 introduced the
- What is the purpose of the
Symbol
type?Symbol
is a primitive data type that represents a unique and immutable identifier. It is often used to avoid naming conflicts in object properties.
Practical Questions
- How would you clone an object in JavaScript?
- Shallow clone:
Object.assign({}, obj)
or{...obj}
- Deep clone: Using
JSON.parse(JSON.stringify(obj))
or libraries like Lodash’s_.cloneDeep()
- Shallow clone:
- Explain how
call
,apply
, andbind
methods work.call
: Invokes a function with a giventhis
value and arguments provided individually.apply
: Invokes a function with a giventhis
value and arguments provided as an array.bind
: Returns a new function with a giventhis
value and arguments, which can be invoked later.
- What are higher-order functions?
- Higher-order functions are functions that take other functions as arguments or return functions as their result.
- How do you handle errors in JavaScript?
- Using
try...catch
blocks to catch and handle exceptions. Using.catch()
method in promises.
- Using
- What are
setTimeout
andsetInterval
, and how do they differ?setTimeout
executes a function once after a specified delay.setInterval
repeatedly executes a function at specified intervals.