MockReal Logo
Home
BlogPricing
For Employers →
  1. Home
  2. Questions
  3. Explain in length the difference between map and forEach.

Explain in length the difference between map and forEach.

Technicaljunior full stack developerFrontend DeveloperBackend Developer

map creates a new array by applying a function to each element, while forEach simply executes a function on each element without returning anything. For example, if I want to transform data, I’d use map to get a new array of transformed values. On the other hand, forEach is useful for side effects, like logging or updating a UI, where I don’t need a new array.

In summary, use map when you need a result and forEach when you just want to perform an action.

More Questions

  • Can a file with a filename different than index.php/index.html be set as directory default and explain briefly how?
  • Consider the following JS function. What will the following code do?
  • Consider the functions below. Will they return the same thing? Select the most accurate response.
  • Did you ever have a client who was really tough to work with? Talk about your experience.
  • Did you ever use GULP, LESS, SASS, GRUNT, NPM, GIT, BOWER, WEBPACK, ELIXIR?
  • Did you happen to use flexbox and explain a few different use scenarios?
  • Did you have any experience with uncommon types of redirections, why did you use them and what were the drawbacks?
  • Does a <section> go inside an <article>, or is it the other way around? Explain please, give us some use cases.
  • Do you know of any different conventions of naming CSS elements and selectors?
  • Explain in length the difference between call and apply.
MockReal Logo

Spoken interview practice for technical professionals

Product

  • Pricing
  • Questions
  • Positions
  • Resumes
  • For Employers →

Company

  • Careers
  • About Us
  • Contact
  • Blog

Legal

  • Privacy Policy
  • Terms of Service
  • Cookie Policy

© 2025 MockReal. Spoken interview practice. All rights reserved.