JavaScript Questions

1. JavaScript is primarily a ___ language.

A. Compiled

B. Interpreted

C. Assembly

D. Markup

      B. Interpreted

2. Why is JavaScript called single-threaded?

A. It can only use one CPU core

B. It executes one operation at a time in sequence

C. It doesn’t support functions

D. It lacks memory management

      B. It executes one operation at a time in sequence

3. What is hoisting in JavaScript?

A. Moving variable declarations to the top of their scope

B. Deleting unused variables

C. Converting JS to machine code

D. A type of error

      A. Moving variable declarations to the top of their scope

4. What distinguishes let from var?

A. let is function-scoped, var is block-scoped

B. let is block-scoped, var is function-scoped

C. Both are identical

D. let is global by default

      B. let is block-scoped, var is function-scoped

5. A closure in JavaScript is:

A. A function bundled with its lexical environment

B. A way to delete variables

C. A type of loop

D. An error-handling mechanism

      A. A function bundled with its lexical environment

6.The value of this inside an arrow function:

A. Refers to the global object

B. Is dynamically scoped

C. Inherits from the parent scope

D. Always equals undefined

      C. Inherits from the parent scope

7. Event bubbling in JavaScript means:

A. Events propagate from child to parent elements

B. Events stop at the target element

C. Events are canceled automatically

D. Events only work on buttons

      A. Events propagate from child to parent elements

8. JavaScript uses:

A. Classical inheritance

B. Prototypal inheritance

C. Multiple inheritance

D. No inheritance model

      B. Prototypal inheritance

9. NaN stands for:

A. Not a Node

B. Not a Number

C. Null and None

D. New Assignment Notation

      B. Not a Number

10. What does 'use strict' do?

A. Enables stricter syntax checking

B. Disables all errors

C. Makes JS behave like Python

D. Slows down execution

      A. Enables stricter syntax checking

11. Callback hell refers to:

A. Nested callbacks making code unreadable

B. Too many comments in code

C. A browser rendering issue

D. Memory leaks in functions

      A. Nested callbacks making code unreadable

12. A Promise in JavaScript represents:

A. A completed operation

B. A value that may be available now, later, or never

C. A synchronous task

D. An HTML element

      B. A value that may be available now, later, or never

13. async/await is:

A. A replacement for Promises

B. Syntactic sugar over Promises

C. A type of loop

D. Used only in Node.js

      B. Syntactic sugar over Promises

14. CORS stands for:

A. Cross-Origin Resource Sharing

B. Centralized Object Request System

C. Common Output Response Standard

D. Cache Object Retrieval Scheme

      A. Cross-Origin Resource Sharing

15. Web Workers allow:

A. Multi-threading in JavaScript

B. Faster DOM manipulation

C. Automatic garbage collection

D. CSS animations

      A. Multi-threading in JavaScript

16. The event loop handles:

A. Synchronous tasks only

B. Asynchronous callback execution

C. Memory allocation

D. CSS rendering

      B. Asynchronous callback execution

17. A Map is preferred over an Object when:

A. Keys are always strings

B. Insertion order matters

C. JSON serialization is needed

D. Memory usage must be maximized

      B. Insertion order matters

18. Debouncing is used to:

A. Limit how often a function executes

B. Speed up animations

C. Delete unused variables

D. Encrypt data

      A. Limit how often a function executes

19. SameSite=Lax prevents:

A. All cookies

B. Cross-site request forgery (CSRF)

C. JavaScript execution

D. CSS injections

      B. Cross-site request forgery (CSRF)

20. Shadow DOM is used for:

A. Global styling

B. Encapsulating component markup/styles

C. Server-side rendering

D. Database queries

      B. Encapsulating component markup/styles

Scroll to Top