Invented by American computer scientist John McCarthy in 1959, garbage collection was designed to make manual memory management more straightforward in Lisp. Garbage collection is a type of automated memory management. The garbage collector attempts to reclaim memory that has been allocated by the program but is no longer used—also known as garbage. Today, garbage collectors are used in many programming languages, including Java, Python, and JavaScript. A garbage collector works by periodically scanning the heap (the area of memory where objects are stored) for objects that are no longer reachable by the program. When such an object is found, the garbage collector reclaims the memory used by that object, freeing it up for other objects. This helps to prevent memory leaks, which can cause a program to run out of memory and crash. In general, garbage collectors allow programmers to focus on other aspects of their code, without having to worry about manually managing memory.
What Does Require Do
When a module is loaded using the require() function, the module’s code is executed and the exports object of the module is returned. The require() function can be used to load local files as well as modules installed from npm.