JavaScript Interview Questions and Answers
Basic JavaScript Concepts
1. What is JavaScript?
JavaScript is a lightweight, interpreted programming language that enables interactive web pages.
It is used for both client-side and server-side development.
2. Explain the difference between undefined and null.
- undefined means a variable has been declared but not assigned a value.
- null is an intentional absence of any value assigned by the developer.
3. What are the different data types in JavaScript?
JavaScript has the following data types:
- Primitive: string, number, boolean, null, undefined, bigint, symbol
- Non-primitive: object, array, function
4. What is the difference between == and ===?
- == (abstract equality) checks for value equality, performing type coercion if necessary.
- === (strict equality) checks for both value and type equality.
5. How do you declare a variable in JavaScript?
- Using var, let, or const.
6. What is the use of the typeof operator?
It determines the type of a variable. Example: typeof 42 returns 'number'.
7. Explain hoisting in JavaScript.
Hoisting is JavaScript's behavior of moving variable and function declarations to the top of their
containing scope before code execution.
8. How does JavaScript handle asynchronous operations?
Using callbacks, promises, and async/await.
9. What is the event loop in JavaScript?
It manages asynchronous operations by handling the execution of callbacks from the task queue.
10. Explain the difference between let, const, and var.
- var: Function-scoped, allows re-declaration.
- let: Block-scoped, no re-declaration.
- const: Block-scoped, immutable reference.
(Continued with all 118 questions and answers...)