What does the map() method do in JavaScript?
It creates a new array by calling a provided function on every element in the original array.
Does map() modify the original array?
No, map() does not modify the original array. It returns a new array with transformed values.
What arguments does the callback function in map() take?
The callback function takes up to three arguments: currentValue, index, and the original array.
What is the syntax of map()?
array.map(function(currentValue, index, array) { /* code */ }, thisArg);
Give a simple example of using map().
const nums = [1, 2, 3]; const doubled = nums.map(n => n * 2); // [2, 4, 6]
How is map() different from forEach()?
map() returns a new array with transformed data, while forEach() just executes a function for each element and returns undefined.
Can you chain map() with other array methods?
Yes, map() is often chained with filter(), reduce(), or other methods for data transformation.
What happens if the callback in map() does not return anything?
If the callback doesn’t return a value, map() will fill the new array with undefined values.
Can map() be used on non-array objects?
Only on array-like objects that implement map(), like typed arrays or when converted using Array.from().
Is map() synchronous or asynchronous?
map() is synchronous — it doesn’t wait for async operations inside the callback to finish.