DEV Community

Tamilselvan K
Tamilselvan K

Posted on

Day-43 Interview Questions and Answers (Frontend + Node.js + JavaScript)

1. What is the difference between a function declaration and function expression?

  • Function Declaration: Declared with the function keyword and hoisted.
  function greet() { console.log('Hello'); }
Enter fullscreen mode Exit fullscreen mode
  • Function Expression: Assigned to a variable; not hoisted.
  const greet = function() { console.log('Hello'); }
Enter fullscreen mode Exit fullscreen mode

2. How does setTimeout work?

  • It runs a function after a specified delay asynchronously.
  • Uses the event loop: the function is placed in a task queue after the delay.

3. How do you select elements from the DOM?

  • document.getElementById('id')
  • document.querySelector('selector')
  • document.getElementsByClassName('class')
  • document.querySelectorAll('selector')

4. What is the purpose of async and await in JavaScript?

  • Handle asynchronous operations in a synchronous way.
  • Helps avoid callback hell.
async function fetchData() {
  const data = await fetch('url');
}
Enter fullscreen mode Exit fullscreen mode

5. What is a callback function?

  • A function passed as an argument to another function to be executed later.
setTimeout(() => { console.log('Hello'); }, 1000);
Enter fullscreen mode Exit fullscreen mode

6. What is Node.js and how does it work?

  • Node.js is a JavaScript runtime built on Chrome's V8 engine.
  • Uses non-blocking I/O and an event-driven model to handle multiple connections with a single thread.

7. For Node.js, why does Google use the V8 engine?

  • V8 is fast, compiles JavaScript to native machine code.
  • Provides high performance and efficient memory management.

8. Why is Node.js single-threaded?

  • Node uses a single-threaded event loop for scalability.
  • Handles multiple requests asynchronously using callbacks, promises, and async/await.

9. Can you access DOM in Node.js?

  • No, DOM is a browser-specific API. Node.js runs on the server.

10. How to create a simple HTTP server in Node.js?

const http = require('http');
const server = http.createServer((req, res) => {
  res.end('Hello World');
});
server.listen(3000);
Enter fullscreen mode Exit fullscreen mode

11. What is the difference between synchronous and asynchronous functions?

  • Synchronous: Blocks the execution until the task completes.
  • Asynchronous: Doesn't block. Tasks like API calls, timers are handled in the background.

12. What are the different types of HTTP requests?

  • GET: Retrieve data.
  • POST: Send data.
  • PUT: Update entire resource.
  • PATCH: Update part of a resource.
  • DELETE: Delete resource.
  • OPTIONS, HEAD

13. Explain this keyword.

  • In object: Refers to the object itself.
  • In function (non-strict): Refers to the global object.
  • In strict mode or arrow functions: this is undefined or inherits from the parent scope.

14. What is the difference between undefined and null?

  • undefined: Variable declared but not assigned.
  • null: Intentional assignment to represent no value.

15. What is the difference between == and === in JavaScript?

  • ==: Compares values with type coercion.
  • ===: Strict comparison without type coercion.

16. What are truthy and falsy values?

  • Falsy: false, 0, '', null, undefined, NaN
  • Truthy: Anything that is not falsy.

17. What is the difference between global and local scope?

  • Global Scope: Available anywhere in the code.
  • Local Scope: Available only within functions or blocks.

18. How to optimize a webpage for performance?

  • Compress images.
  • Minify CSS, JS.
  • Use CDN.
  • Lazy load assets.
  • Implement caching.
  • Remove unused code.

19. How to handle CORS in JavaScript?

  • Set headers like:
Access-Control-Allow-Origin: '*'
Enter fullscreen mode Exit fullscreen mode
  • Or handle via backend or use proxies.

20. What is a closure and how does it work?

  • A function that remembers its outer scope, even after the outer function has finished.
function outer() {
  let count = 0;
  return function inner() { count++; }
}
Enter fullscreen mode Exit fullscreen mode

21. Explain CSS positions: relative, absolute, fixed.

  • Relative: Positioned relative to itself.
  • Absolute: Positioned relative to the nearest positioned ancestor.
  • Fixed: Sticks relative to the viewport.

22. What is a media query and how does it work?

  • Used to make responsive designs based on device size.
@media (max-width: 600px) {
  body { background: red; }
}
Enter fullscreen mode Exit fullscreen mode

23. What is SPA (Single Page Application)?

  • Loads a single HTML page.
  • Updates content dynamically without refreshing the entire page.

24. Client-side vs Server-side Rendering

  • Client-side: Rendering happens in the browser.
  • Server-side: Rendering happens on the server; better SEO and faster initial load.

25. Explain npm and yarn.

  • Both are JavaScript package managers.
  • Yarn is generally faster with better caching and offline capabilities.

26. How do you manage version control and collaboration using Git?

  • Branching (git branch)
  • Merging (git merge)
  • Pull requests (collaborative review)
  • Resolving conflicts and version tracking.

27. What are build tools like Vite or Webpack used for?

  • Bundling, transpiling, and optimizing front-end code for development and production.

28. What is the difference between development and production environments?

  • Development: Includes debugging, detailed logs, source maps.
  • Production: Optimized, minified, no source maps, faster.

29. How do you debug a frontend application?

  • Use browser DevTools (Console, Network, Sources).
  • Add breakpoints.
  • Use console.log() for quick checks.

30. Difference between id and class in HTML?

  • id: Unique identifier (#id), used once per page.
  • class: Reusable (.class), used for styling and selecting multiple elements.

31. How to use the CSS box model?

  • Content → Padding → Border → Margin
  • Controls layout spacing in CSS.

32. Difference between arrow function and traditional function.

  • Arrow functions: Don't have their own this, arguments.
  • Shorter syntax.
const add = (a, b) => a + b;
Enter fullscreen mode Exit fullscreen mode

33. Explain em, rem, and px in CSS.

  • px: Absolute pixels.
  • em: Relative to parent font size.
  • rem: Relative to root (html) font size.

34. What are template literals and why are they used?

  • String literals using backticks for interpolation.
`Hello, ${name}`
Enter fullscreen mode Exit fullscreen mode
  • Supports multi-line strings and embedding expressions.

35. Explain var, let, and const.

  • var: Function-scoped, hoisted.
  • let: Block-scoped, not hoisted.
  • const: Block-scoped, cannot be reassigned.

36. Explain synchronous and asynchronous in JavaScript.

  • Synchronous: Runs line by line, blocks execution.
  • Asynchronous: Runs in the background, non-blocking.

37. How does the event loop work in JavaScript?

  • Executes synchronous code first.
  • Moves asynchronous tasks (like setTimeout, promises) to the callback/task queue.
  • Processes them when the call stack is empty.

Conclusion

This numbered format gives a clean overview of the most important frontend, JavaScript, and Node.js concepts for interviews. You can directly use this for your blog or study notes.

Top comments (1)

Collapse
 
dotallio profile image
Dotallio

This is such a handy reference, honestly covers so much ground for quick interview prep! Have you thought about adding some trickier or real-world scenario questions next?