1. What are the key features of JavaScript?
- Lightweight, interpreted language
- Supports object-oriented and functional programming
- First-class functions
- Event-driven and asynchronous
- Used primarily for client-side scripting but also server-side (Node.js)
2. Difference between var, let, and const
- var: Function-scoped, hoisted, can be redeclared
- let: Block-scoped, not hoisted like var, can't be redeclared in same scope
- const: Block-scoped, must be initialized, value can't be reassigned (but objects/arrays can still be mutated)
3. What is hoisting?
Hoisting means variable and function declarations are moved to the top of their scope during compilation.
Example:
console.log(a); // undefined
var a = 10;
4. Explain closures with an example
A closure is when a function retains access to its lexical scope even when executed outside of it.
function outer() {
let count = 0;
return function inner() {
return ++count;
};
}
const counter = outer();
counter(); // 1
counter(); // 25. What is the difference between == and ===?
- == (loose equality): Converts operands before comparing
- === (strict equality): Checks type and value without conversion
'5' == 5 // true
'5' === 5 // false
6. What is event bubbling and capturing?
- Bubbling: Event moves from target to top (child → parent)
- Capturing: Event moves from top to target (parent → child)
You can control this with the addEventListener third parameter.
7. What is the DOM?
The Document Object Model is a tree-like structure representing HTML as objects. JavaScript uses it to read and manipulate web pages dynamically.
8. Difference between null and undefined
- undefined: Variable declared but not assigned
- null: Intentionally set to "no value"
let a; // undefined
let b = null; // explicitly empty
9. What are arrow functions?
Concise function syntax introduced in ES6. They do not bind their own this.
const add = (a, b) => a + b;
10. Explain callback functions
A callback is a function passed as an argument to another function and executed later.
Used in async operations.
function greet(name, callback) {
callback(Hello, ${name});
}
greet('John', msg => console.log(msg));💬 Tap ❤️ for Part-2!