Javascript
Javascript
Interview
Questions
by Rupendra Ragala
Basics & Fundamentals
1.What is JavaScript and how is it different
from Java?
JavaScript is a scripting language mainly used
for dynamic content in web browsers. Java is a
programming language for general-purpose
applications. JavaScript runs in the browser,
Java runs in JVM.
2. Explain let, const, and var.
var: Function scoped, can be hoisted.
let: Block scoped, not hoisted.
const: Block scoped, cannot be reassigned.
3. What is a closure in JavaScript?
A closure is a function that remembers its
outer variables even after the outer function
has returned.
4.What is hoisting?
JavaScript's behavior of moving declarations
to the top. Variables declared with var and
functions are hoisted.
5. Difference between == and ===?
a.==: Compares value (type coercion
allowed).
b.===: Compares value and type (strict
equality).
6. What is the event loop?
The mechanism that handles asynchronous
operations by pushing callbacks into a queue
once the call stack is empty.
7. What are promises?
Promises represent the eventual result of an
asynchronous operation. States: pending,
fulfilled, rejected.
8. What is async/await?
Syntax sugar over promises to write
asynchronous code in a synchronous style.
9. What is the use of this keyword?
Refers to the current execution context. Its
value depends on how a function is called.
10. What is a callback function?
A function passed as an argument to another
function to be executed later.
11. How to select elements in DOM?
document.getElementById('id')
document.querySelector('.class')
document.querySelectorAll('div')
12. What is event delegation?
Handling events at a parent level using
bubbling, reducing the number of event
listeners.