🔹 1. What is JavaScript?
JavaScript is a scripting language used to make web pages interactive. It runs in the browser and is used for dynamic behavior like forms, animations, and API calls.
🔹 2. What are JavaScript data types?
JavaScript has two types:
Primitive:
- String
- Number
- Boolean
- Null
- Undefined
- Symbol
- BigInt
Non-primitive:
- Object
- Array
- Function
🔹 3. Difference between var, let, and const?
| var | let | const |
|---|---|---|
| Function scoped | Block scoped | Block scoped |
| Can be redeclared | Cannot redeclare | Cannot redeclare |
| Can be updated | Can be updated | Cannot be updated |
🔹 4. What is hoisting?
Hoisting is JavaScript behavior where declarations are moved to the top before execution.
Example:
console.log(a);
var a = 10;
Output: undefined
🔹 5. What is scope in JavaScript?
Scope defines where variables can be accessed.
Types:
- Global scope
- Function scope
- Block scope
🔹 6. What is closure?
A closure is a function that remembers variables from its outer function even after execution.
🔹 7. What is an array?
An array is a collection of multiple values in a single variable.
🔹 8. What are array methods?
Common methods:
- map()
- filter()
- reduce()
- push()
- pop()
🔹 9. What is DOM?
DOM (Document Object Model) represents HTML structure as a tree.
🔹 10. What is DOM manipulation?
Changing HTML elements using JavaScript.
🔹 11. What are events in JavaScript?
Events are user actions like click, hover, keypress.
🔹 12. What is event listener?
It is used to attach an event to an element.
button.addEventListener("click", function() {
alert("Clicked!");
});
🔹 13. What is == and ===?
| == | === |
|---|---|
| Checks value | Checks value + type |
🔹 14. What is NaN?
NaN means “Not a Number”.
🔹 15. What is undefined?
A variable that is declared but not assigned a value.
🔹 16. What is null?
Null means intentional empty value.
🔹 17. What is function in JavaScript?
A block of reusable code.
🔹 18. What is arrow function?
Short syntax for functions.
const add = (a, b) => a + b;
🔹 19. What is callback function?
A function passed as an argument to another function.
🔹 20. What is higher-order function?
A function that takes another function as input or returns a function.
🔹 21. What is JSON?
JSON is a format to store and exchange data.
🔹 22. What is localStorage?
Stores data permanently in browser.
🔹 23. What is sessionStorage?
Stores data for one session only.
🔹 24. Difference between localStorage and sessionStorage?
| localStorage | sessionStorage |
|---|---|
| Permanent | Temporary |
| Data remains | Data cleared on tab close |
🔹 25. What is strict mode?
It helps catch errors in JavaScript.
"use strict";
🔹 26. What is event bubbling?
Event moves from child element to parent.
🔹 27. What is event capturing?
Event moves from parent to child.
🔹 28. What is setTimeout?
Runs code after delay.
🔹 29. What is setInterval?
Runs code repeatedly after interval.
🔹 30. What is Promise?
A promise handles asynchronous operations.
States:
- Pending
- Fulfilled
- Rejected
🔹 31. What is async/await?
Simplifies asynchronous code writing.
🔹 32. What is error handling?
Using try-catch block to handle errors.
🔹 33. What is try-catch?
Used to handle runtime errors.
🔹 34. What is typeof operator?
Returns data type of variable.
🔹 35. What is type coercion?
Automatic conversion of data types.
🔹 36. What is == vs ===?
== compares value, === compares value + type.
🔹 37. What is template literal?
String with backticks allowing variables.
`Hello ${name}`
🔹 38. What is destructuring?
Extract values from arrays or objects.
🔹 39. What is spread operator?
Expands elements of array or object.
🔹 40. What is rest operator?
Collects multiple values into one array.
🔹 41. What is map function?
Creates a new array by transforming elements.
🔹 42. What is filter function?
Returns filtered array based on condition.
🔹 43. What is reduce function?
Reduces array to single value.
🔹 44. What is forEach?
Loops through array elements.
🔹 45. What is IIFE?
Immediately Invoked Function Expression.
🔹 46. What is memory leak?
Unused memory not released.
🔹 47. What is garbage collection?
Automatic memory cleanup.
🔹 48. What is prototype?
Mechanism for inheritance in JavaScript.
🔹 49. What is inheritance?
One object can inherit properties of another.
🔹 50. Why is JavaScript important?
It makes websites interactive, dynamic, and modern.