General

Backend with JavaScript – Foundation

2 Mins read

Level 1: Core JavaScript (Backend Foundation)

1. What is the event loop in JavaScript?

Expected answer:
JavaScript is single-threaded; the event loop manages execution of synchronous code and handles async callbacks (via call stack, callback queue, microtask queue).


2. Difference between setTimeout and Promise.then execution?

Expected answer:
Promise.then runs in the microtask queue (higher priority), while setTimeout runs in the callback queue (lower priority), so promises execute first.


3. What is async/await and how does it work?

Expected answer:
Syntactic sugar over Promises. await pauses execution inside an async function until the Promise resolves/rejects.


4. Difference between == and ===?

Expected answer:
== does type coercion, === checks both value and type (strict equality).


5. What happens if you don’t handle a rejected Promise?

Expected answer:
It results in an unhandled promise rejection, which can crash the Node.js process (or log warnings depending on config).


🟡 Level 2: HTTP & REST Fundamentals

6. What is REST?

Expected answer:
An architectural style using HTTP methods to perform CRUD operations on resources (stateless, client-server separation).


7. Difference between GET and POST?

Expected answer:
GET retrieves data (no side effects), POST sends data to create resources (can modify server state).


8. What are common HTTP status codes?

Expected answer:
200 (OK), 201 (Created), 400 (Bad Request), 401 (Unauthorized), 404 (Not Found), 500 (Server Error).


9. What is statelessness in REST?

Expected answer:
Each request contains all required information; server doesn’t store client session state.


10. What is the difference between PUT and PATCH?

Expected answer:
PUT replaces the entire resource; PATCH updates partial fields.


🟠 Level 3: Backend Thinking & Node.js Concepts

11. How does Node.js handle multiple requests if it is single-threaded?

Expected answer:
Uses non-blocking I/O and event loop; heavy tasks are delegated to system threads or worker pool.


12. What is middleware in backend systems?

Expected answer:
Functions that run before/after request handlers to process requests (e.g., logging, auth, validation).


13. What is JSON and why is it commonly used?

Expected answer:
Lightweight data format used for client-server communication; easy to parse in JavaScript.


14. What is CORS?

Expected answer:
Security mechanism that controls cross-origin requests from browsers.


15. What is input validation and why is it important?

Expected answer:
Ensures incoming data is correct/safe; prevents bugs, security issues (like injection attacks).


🔵 Level 4: Debugging & Developer Tools Awareness

16. How would you debug a failing API?

Expected answer:
Check logs, inspect request/response, use browser dev tools/Postman, verify payload and status codes.


17. What can you do with browser developer tools (Network tab)?

Expected answer:
Inspect API calls, headers, payload, response, timing, status codes.


18. What is a 500 error vs 400 error?

Expected answer:
400 = client mistake, 500 = server-side failure.


19. How would you test an API without frontend?

Expected answer:
Use tools like Postman/cURL to send requests and inspect responses.


20. What are logs and why are they important?

Expected answer:
Records of application activity used for debugging, monitoring, and tracing issues.


🔴 Level 5: Problem Solving & Applied Scenarios

21. If an API is slow, how would you investigate?

Expected answer:
Check DB queries, network latency, logs, response time, optimize heavy operations.


22. How would you design an API for “Create User”?

Expected answer:
POST /users, validate input, store data, return 201 + created resource.


23. What happens if two users update the same data simultaneously?

Expected answer:
Race condition; need handling (locking, versioning, last-write-wins, etc.).


24. How would you handle errors in an API?

Expected answer:
Use try-catch, return meaningful status codes and messages, log errors.


25. What is the difference between synchronous and asynchronous code?

Expected answer:
Sync blocks execution; async allows non-blocking execution and better performance.