Without getting into too much detail about how computers allocate memory, suffice it to say that an improperly written program can cause a memory leak by not properly releasing and recycling memory, which can cause the program to crash. As opposed to some lower-level languages, JavaScript is supposed to automatically garbage collect: the practice of automatic memory management that releases memory by destroying unneeded pieces of data. However, there are cases when improperly written code can cause a memory leak that garbage collection doesn't handle.
Since JavaScript runs client-side, it can be hard to decipher exactly what's going on in your program. Luckily, there are tools to help. Let's work through an example of a program that will allocate a lot of memory. Take a look at this example: https://github.com/PacktPublishing/Hands-on-JavaScript-for-Python-Developers/blob/master/chapter-9/memory-leak/index.html.
If you look at the included JavaScript file...