NEWNew questions added!Explore now

Interview preparation guide · Updated 2026

JavaScript Interview Questions with Answers and Code (2026)

A strong JavaScript interview answer connects language behavior to a concrete example. You should be able to reason about scope, closures, prototypes, coercion, asynchronous execution, and common data transformations, then write a small implementation and test its edge cases. Clear reasoning matters more than recalling obscure trivia.

By FrontendPro Editorial Team Last reviewed August 8, 2026

What you need to know

Use these topic clusters as a checklist. Each answer should define the concept, show where it matters, and include a concrete example or trade-off.

Practice questions with answers

Open a question for a direct explanation, detailed answer, related concepts, and runnable code where the problem includes a coding exercise.

JavaScript interview questions

  1. Write mergeSorted(a, b) merging two sorted arrays into one sorted array, without sort()Advanced · Answer and explanation
  2. Write mostFrequentChar(str) returning the most frequent character (null for an empty string)Intermediate · Answer and explanation
  3. Write isAnagram(a, b) checking whether two strings are anagrams (ignoring case and spaces)Intermediate · Answer and explanation
  4. Write twoSum(nums, target) returning the indices of the two numbers adding up to target (empty array if none)Intermediate · Answer and explanation
  5. Write groupByLength(words) that groups an array of strings into an object keyed by lengthIntermediate · Answer and explanation
  6. Write flatten(arr) that flattens a nested array at any depthIntermediate · Answer and explanation
  7. Write chunk(arr, size) that splits an array into groups of sizeIntermediate · Answer and explanation
  8. Write titleCase(str) that uppercases the first letter of every word and lowercases the restBasic · Answer and explanation
  9. Write fizzBuzz(n) returning the FizzBuzz sequence from 1 to n as an array of stringsBasic · Answer and explanation
  10. Write countVowels(str) that counts the vowels in a stringBasic · Answer and explanation
  11. Write a function that removes duplicate values from an arrayIntermediate · Answer and explanation
  12. Write a function that checks whether a string is a palindromeBasic · Answer and explanation
  13. Write a function that finds the largest number in an arrayBasic · Answer and explanation
  14. Write a function that sums the numbers in an arrayBasic · Answer and explanation
  15. Write a function that reverses a stringBasic · Answer and explanation
  16. When would you use document.write()?Advanced · Answer and explanation
  17. Is TypeScript worth the trade-offs?Advanced · Answer and explanation
  18. How do you organise a codebase?Intermediate · Answer and explanation
  19. How do you share code between files?Basic · Answer and explanation
  20. How do you make an SPA SEO-friendly?Intermediate · Answer and explanation
  21. What is the same-origin policy?Intermediate · Answer and explanation
  22. How do you store auth tokens securely?Advanced · Answer and explanation
  23. How do you find security vulnerabilities?Intermediate · Answer and explanation
  24. Why does input validation matter for security?Intermediate · Answer and explanation
  25. How do you prevent clickjacking?Advanced · Answer and explanation
  26. Which security headers should you set?Intermediate · Answer and explanation
  27. What is Content Security Policy (CSP)?Intermediate · Answer and explanation
  28. How do you handle sensitive data?Intermediate · Answer and explanation
  29. How do you prevent SQL injection?Intermediate · Answer and explanation
  30. What is CSRF and how do you prevent it?Intermediate · Answer and explanation

How to prepare efficiently

Do not memorize a long script. Practice a repeatable answer structure: direct answer, short example, edge case, and trade-off.

  • State the relevant JavaScript rule first, then walk through a minimal code example.
  • For output questions, write down the call stack and queue transitions in execution order.
  • For implementation questions, clarify inputs, outputs, timing behavior, and edge cases before coding.
  • Test empty values, repeated calls, error paths, and boundary conditions instead of only the happy path.
  • Compare related concepts such as debounce versus throttle or microtasks versus tasks.