What is JavaScript primarily used for?
→ JavaScript is used for creating dynamic and interactive web pages.
What is the difference between let, var, and const?
→ var has function scope, let has block scope, and const is block-scoped and
immutable.
What is the difference between == and === in JavaScript?
→ == checks for value equality with type conversion, while === checks both
value and type.
What is the purpose of typeof in JavaScript?
→ It returns the data type of a given variable.
What is the difference between null and undefined?
→ null is an assigned empty value, while undefined means a variable has been
declared but not assigned.
What is a closure in JavaScript?
→ A closure is a function that remembers variables from its outer scope even
after the outer function has executed.
What is the difference between function declaration and function expression?
→ Function declarations are hoisted, while function expressions are not.
What is an Immediately Invoked Function Expression (IIFE)?
→ An IIFE is a function that runs immediately after being defined, using
(function() {})();.
What is the purpose of this in JavaScript?
→ this refers to the object that is executing the function.
How does arrow function syntax affect this in JavaScript?
→ Arrow functions inherit this from their surrounding scope instead of creating
their own.
What is event delegation in JavaScript?
→ A technique where a parent element listens for events on its child elements
using event bubbling.
What is the difference between synchronous and asynchronous JavaScript?
→ Synchronous JavaScript executes line by line, while asynchronous JavaScript
does not block execution.
What is the purpose of the Promise object in JavaScript?
→ A Promise represents a value that may be available now, later, or never.
What are async and await in JavaScript?
→ async functions return a promise, and await pauses execution until the
promise resolves.
What is the difference between map(), filter(), and reduce()?
→ map() transforms an array, filter() returns elements that meet a condition, and
reduce() accumulates values into one result.
What is the difference between forEach() and map()?
→ forEach() does not return a new array, while map() returns a new transformed
array.
What is hoisting in JavaScript?
→ Hoisting moves variable and function declarations to the top of their scope
before execution.
What is the difference between call(), apply(), and bind()?
→ call() invokes a function with arguments separately, apply() takes an array of
arguments, and bind() returns a new function with this bound.
What is the purpose of Object.freeze() in JavaScript?
→ It makes an object immutable, preventing properties from being modified or
added.
What is the difference between deep copy and shallow copy in JavaScript?
→ A shallow copy shares references, while a deep copy creates completely
independent copies of objects.
What is a prototype in JavaScript?
→ A prototype is an object from which other objects inherit properties and
methods.
What is the difference between localStorage, sessionStorage, and cookies?
→ localStorage stores data permanently, sessionStorage clears data on session
end, and cookies are sent with every request.
What is a higher-order function in JavaScript?
→ A function that takes another function as an argument or returns a function.
What is the purpose of JSON.stringify() and JSON.parse()?
→ JSON.stringify() converts an object to a JSON string, while JSON.parse()
converts a JSON string to an object.
What is the event loop in JavaScript?
→ The event loop manages asynchronous operations by continuously checking
the call stack and task queue.
What is the difference between document.querySelector() and
document.getElementById()?
→ querySelector() selects elements using CSS selectors, while getElementById()
selects by id.
What is the purpose of setTimeout() and setInterval()?
→ setTimeout() executes a function after a delay, while setInterval() executes
repeatedly at intervals.
What is destructuring in JavaScript?
→ A syntax that allows extracting values from arrays or objects into variables.
What is the spread operator (...) used for in JavaScript?
→ It expands iterable elements like arrays or objects into individual elements.
What is the difference between ES5 and ES6 in JavaScript?
→ ES6 introduced new features like let, const, arrow functions, classes, and
template literals.