Answer: JavaScript is a lightweight, interpreted programming language used primarily for web development to create dynamic and interactive effects within web browsers.
2. Which company developed JavaScript?
Answer: Netscape.
3. What is the difference between == and === in JavaScript?
Answer: == checks for equality with type coercion, while === checks for strict equality without type coercion.
4. What is NaN in JavaScript?
Answer: NaN stands for “Not-a-Number.” It is a value representing something that is not a legal number.
5. What will be the output of typeof NaN?
Answer: “number”.
6. What are the different data types in JavaScript?
Answer: The data types are: undefined, null, boolean, string, number, bigint, symbol, and object.
7. What does null represent in JavaScript?
Answer: null is an assignment value representing “no value.”
8. Is JavaScript case-sensitive?
Answer: Yes, JavaScript is case-sensitive.
9. What is a closure in JavaScript?
Answer: A closure is a function that remembers its outer variables and can access them.
10. What is the this keyword in JavaScript?
Answer: this refers to the context in which a function is called.
11. What will console.log(typeof null) return?
Answer: “object”.
12. What is an Immediately Invoked Function Expression (IIFE)?
Answer: An IIFE is a function that runs as soon as it is defined.
13. What is the difference between let and var?
Answer: let has block scope, while var has function scope.
14. Can you reassign values to const variables?
Answer: No, const variables cannot be reassigned, but properties of const objects can be modified.
15. What is the purpose of Array.prototype.map?
Answer: .map() creates a new array by applying a function to each element of an existing array.
16. What is a promise in JavaScript?
Answer: A promise is an object representing the eventual completion or failure of an asynchronous operation.
17. What does JSON.stringify() do?
Answer: It converts a JavaScript object into a JSON string.
18. What is the purpose of JSON.parse()?
Answer: It parses a JSON string and converts it to a JavaScript object.
19. What is hoisting in JavaScript?
Answer: Hoisting is the behavior where variable and function declarations are moved to the top of their scope before code execution.
20. What is the output of console.log([] + {})?
Answer: “[object Object]”.
21. What is the output of console.log({} + [])?
Answer: 0, as an empty object is followed by an empty array in this context.
22. What is the purpose of use strict?
Answer: It enables strict mode, catching common coding errors and “unsafe” actions.
23. What is an arrow function?
Answer: An arrow function is a concise way to write functions using =>.
24. What is event bubbling in JavaScript?
Answer: Event bubbling is a process where an event starts from the deepest element and propagates up to the parent elements.
25. What does isNaN() do?
Answer: It checks if a value is NaN (Not-a-Number).
26. What is destructuring in JavaScript?
Answer: Destructuring allows unpacking values from arrays or properties from objects into distinct variables.
27. What does typeof operator do?
Answer: It returns the data type of a variable.
28. What is the difference between for...of and for...in?
Answer: for...of iterates over iterable objects, for...in iterates over properties.
29. What does Array.prototype.reduce() do?
Answer: It reduces an array to a single value by applying a function to each element.
30. How can you create a deep copy of an object?
Answer: Use JSON.parse(JSON.stringify(object)) or structured cloning.
31. What is a prototype in JavaScript?
Answer: A prototype is an object from which other objects inherit properties.
32. What does === operator compare?
Answer: Value and type.
33. What is the output of console.log(typeof function(){})?
Answer: “function”.
34. What is a callback function?
Answer: A function passed as an argument to another function to be called later.
35. What are higher-order functions?
Answer: Functions that take other functions as arguments or return them.
36. What is the difference between synchronous and asynchronous code?
Answer: Synchronous code executes sequentially; asynchronous code allows tasks to run independently of the main thread.
37. What does the Array.prototype.filter() method do?
Answer: It creates a new array with elements that pass a test.
38. What is the difference between slice() and splice()?
Answer: slice() copies parts of an array; splice() modifies the original array by adding/removing elements.
39. What are template literals in JavaScript?
Answer: Template literals are strings enclosed by backticks (“) and can embed expressions with ${}.
40. What are JavaScript promises?
Answer: Objects that represent the eventual completion (or failure) of an asynchronous operation.
41. What is event delegation?
Answer: A technique to handle events at a higher level for dynamic elements.
42. What is the use of Function.prototype.bind()?
Answer: It creates a new function with a specific this context.
43. What is a module in JavaScript?
Answer: Code that is encapsulated for reuse, often using ES6 import and export.
44. What does Promise.all() do?
Answer: It waits for all promises to resolve or one to reject.
45. What is an async function?
Answer: A function that returns a promise and allows await.
46. What is debouncing in JavaScript?
Answer: A technique to limit function calls during repetitive events.
47. What is throttling in JavaScript?
Answer: A technique to limit function calls to a specified time frame.
48. How do you remove duplicates from an array?
Answer: Using new Set(array) or Array.from(new Set(array)).
49. What is destructuring assignment?
Answer: Syntax to unpack arrays or objects into variables.