A forEach loop is used to iterate over an array and execute a callback function for each element in the array. It does not provide access to the index of the current element or the ability to break out of the loop. On the other hand, a for loop gives the developer more control over the iteration process, including the ability to access the index of the current element and break out of the loop.
A stack can be implemented using an array and the push() and pop() methods. The push() method is used to add an element to the top of the stack and the pop() method is used to remove the element from the top of the stack. A queue can be implemented using an array and the shift() and push() methods. The shift() method is used to remove the first element in the queue and the push() method is used to add an element to the end of the queue. Alternatively, a linked list can be used to implement both a stack and a queue.
A shallow copy is a copy of an object that references the same memory as the original object. This means that if the original object is modified, the shallow copy will also be modified. A deep copy, on the other hand, creates a new memory location for the copied object, so changes to the original object will not affect the copied object.
A debounce function is used to limit the rate at which a function can be called. This can be implemented by using the setTimeout() method to delay the execution of the function and then clearing any previous timeout before setting a new one. This ensures that the function is only called once the specified delay has passed since the last call.
A regular function is defined using the function keyword, whereas an arrow function uses the “=>” syntax. Arrow functions do not have their own this keyword, and instead inherit the this value from the surrounding scope. They also do not have a “arguments” object and cannot be used as constructors
The map() method creates a new array with the results of calling a provided function on every element in the calling array. The filter() method creates a new array with all elements that pass the test implemented by the provided function.