🔹 Basic JavaScript Questions
What is JavaScript?
JavaScript is a programming language used to make websites interactive (like buttons, forms, animations).How is JavaScript different from Java?
Java is a full programming language (used for apps, backend, etc.). JavaScript mainly runs in browsers for web pages.What are the data types in JavaScript?
Common ones:String
,Number
,Boolean
,Object
,Array
,null
,undefined
,Symbol
,BigInt
.Difference between
var
,let
, andconst
?var
: old way, not block-scoped.let
: new, block-scoped.const
: same aslet
but cannot be changed.
What is hoisting?
JavaScript moves variable and function declarations to the top before running code.Difference between
==
and===
?==
compares value only (allows type conversion).===
compares value and type (strict).
What are truthy and falsy values?
Truthy: values that act as
true
(like"hello"
,1
).Falsy: values that act as
false
(like0
,""
,null
,undefined
,NaN
,false
).
What is
typeof
?
It shows the data type of a value, e.g.,typeof 5
returns"number"
.How do you declare a function?
What are arrow functions?
A shorter way to write functions:
🔹 Scope & Closures
Function vs block scope?
var
is function-scoped.let
andconst
are block-scoped (work only inside{}
).
What is a closure?
A function that remembers variables from its outer function, even after the outer function finishes.Why are closures useful?
They help in keeping data private or building functions that remember state.What is lexical scope?
Inner functions can use variables from outer functions (where they were defined, not called).
🔹 Functions and Objects
What are higher-order functions?
Functions that take other functions as arguments or return a function.Function declaration vs expression?
Declaration:
function sum() {}
Expression:
const sum = function() {}
What is
call
,apply
, andbind
?
They let you run a function with a customthis
value.
call
: pass arguments normallyapply
: pass arguments in arraybind
: returns a new function with fixedthis
.
What is
this
in JavaScript?
Refers to the object that is calling the function.How does
this
behave in arrow functions?
Arrow functions don’t have their ownthis
, they use thethis
of the outer function.What is object destructuring?
Breaking an object into variables:
🔹 Arrays and Strings
Common array methods?
map
: change each itemfilter
: pick some itemsreduce
: combine into onepush/pop
,shift/unshift
: add/remove
How to remove duplicates from array?
How to sort an array of numbers?
How to reverse a string?
Difference between
slice
andsplice
?
slice
: copies part of array.splice
: removes/changes original array.
🔹 Asynchronous JavaScript
What is a callback?
A function passed to another function to run later.What are Promises?
A way to handle async code (something that will finish later).What is
async/await
?
A cleaner way to write Promises.What is the event loop?
It helps JavaScript handle many tasks (like clicks, timers) one by one.Microtasks vs Macrotasks?
Microtasks (Promises) run before macrotasks (likesetTimeout
).
🔹 DOM Manipulation & Events
What is the DOM?
It’s how JavaScript sees and controls a webpage.How to select elements?
document.getElementById
,querySelector
, etc.How to handle events?
Event bubbling vs capturing?
Bubbling: event moves from inner to outer.
Capturing: outer to inner.
What is event delegation?
Attach one event listener to a parent to handle child events.
🔹 Error Handling
How to handle errors?
Usetry...catch
.What is
try...catch
?
A block that runs code and catches any errors.Difference between
throw
andtry-catch
?throw
creates an error,try-catch
catches and handles it.
🔹 ES6+ Features
What is a template literal?
A way to include variables in strings:
Default parameters?
Set default value if none is passed:
Rest and spread?
Rest
...args
: collect values into an array.Spread
...arr
: split array into values.
for...of
vsfor...in
?
for...of
: for arraysfor...in
: for objects
What are classes?
A way to create objects using a blueprint.
🔹 Advanced Concepts
What is a prototype?
A hidden object from which other objects inherit.What is prototypal inheritance?
Objects can share properties using prototypes.Difference between
null
andundefined
?
null
: empty on purposeundefined
: not assigned yet
What is a memory leak?
When your code keeps using memory but doesn’t free it.How does garbage collection work?
JavaScript removes unused data automatically.What are modules?
Code files you can import/export to organize JavaScript better.What is debouncing/throttling?
Techniques to control how often a function runs (like on scroll or keypress).