Weakmap and weakset

4 0 0
                                        

weakmap and weakset - it functions the same with map and set respectively but the difference is both accepts only objects as keys and once the object is not needed or nulled, it will be garbage collected automatically along with its values. It is usually use for temporary additional storage. Regular maps could not erase its own object key and values when the object key is nulled. I could not confirmed this though because both WeakMap and Map returned undefined when the object key is nulled. This is because you cannot see or know if the garbage collector functions right away.

syntax:

let name = new WeakMap();

let name = new WeakSet();

Note: This creates an empty weak map and empty weak set. You can then use their defined functions. Like the set(key) and get(key) from WeakMap. Their defined functions though is limited only compare to the regular maps and sets. Like the WeakSet, it has only three defined functions which is add(key, value), delete(key), and has(key).


======================

Note: 

I will try to update javascript every Sunday. I am going to change my schedule since I will be focusing on spring and android. For java and kotlin, I am going to set three days each but just an hour per day. I am not sure if I am going to put Spring notes and Android notes because they are too wide to study. The reason why I am changing my studying topic is when the company hires a java developer, they assumed that you know spring or if they hire a Kotlin developer, they assumed that you know android. So, I will be focusing on these two first.

Javascript ProgrammingWhere stories live. Discover now