<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Erkand Imeri on Medium]]></title>
        <description><![CDATA[Stories by Erkand Imeri on Medium]]></description>
        <link>https://medium.com/@erkand.imeri?source=rss-202785ebef11------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1MEkFIss-NeuAu93duLEhg.jpeg</url>
            <title>Stories by Erkand Imeri on Medium</title>
            <link>https://medium.com/@erkand.imeri?source=rss-202785ebef11------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 16:30:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@erkand.imeri/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[3 key insights I gained from reading “Psychology of Money”]]></title>
            <link>https://medium.com/@erkand.imeri/3-key-insights-i-gained-from-psychology-of-money-2702a27554f2?source=rss-202785ebef11------2</link>
            <guid isPermaLink="false">https://medium.com/p/2702a27554f2</guid>
            <category><![CDATA[money]]></category>
            <category><![CDATA[finance]]></category>
            <dc:creator><![CDATA[Erkand Imeri]]></dc:creator>
            <pubDate>Thu, 09 May 2024 13:43:24 GMT</pubDate>
            <atom:updated>2024-05-09T13:56:18.947Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TX5qNwZiguNiLWFR" /><figcaption>Photo by <a href="https://unsplash.com/@timbatec?utm_source=medium&amp;utm_medium=referral">Pepi Stojanovski</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Howdy to all readers,</p><p>Although I don’t consider myself a bibliophile and lack the consistency of reading books, I consider “Psychology of Money” a remarkable book. Each chapter uses storytelling to engage the reader, hooking them into the chapter and its outcomes. Unmistakably, this book has received many good reviews and is full of wisdom.</p><p>Below, I am listing three outcomes I remember from this book, signifying that there are far more outcomes which I either forgot or cannot recall at the moment. “Psychology of Money” is not just a book but a reference of wisdom. Each time you can open it and read a specific chapter you’ll get something out of it, it’s worth re-reading.</p><ol><li><strong>Enough</strong></li></ol><p>Enough is a simple word without context but Psychology of Money emphasize that “enough” is knowing when one should not go further, should think whether risking everything you have for a trivial win is worth it, knowing when it’s enough is crucial. This doesn’t really mean that enough is sticking in comfort zone, not at all, enough is a balanced philosophy, don’t get too accustomed to risking everything you have because eventually you might run out of luck and lose everything.</p><p><strong>2. Nothing is as good or as bad as it seems</strong></p><p>We people have the tendency to exaggerate our personal experiences, either we bleach out our achievements more than they really were or we try to depict them as worse than they really were, like for example Conspiracy Theories are a favorite thing for a lot of people, it depicts the situation worse as they really are.</p><p>Always remember: <em>Nothing is as good or as bad as it seems</em></p><p><strong>3. You don’t need a specific reason to save</strong></p><p>Saving for the sake of it, is a game changer, just save, you don’t really need a specific reasons to save money: like for a vacation, buying a new car, buying a home. Yeah, we have our own reasons to save, but saving for the sake of it is a game changer and crucial. We never know the outcomes of life so those savings eventually will become handy to our future-self.</p><p><strong>Closing thoughts</strong></p><p>To conclude, “Psychology of Money” is more than a financial book, it gives us a philosophical lens through which we can view our behaviour, decisions and interactions we make with money. As we navigate through the book we learn that our relationship with money is deeply personal and psychological.</p><p>I think this book is more than a financial book, rather philosophical and psychological relatable to each one of us because the way the chapters are explained through narrating real-life stories is remarkable.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2702a27554f2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why use WeakMaps in JavaScript?]]></title>
            <link>https://medium.com/@erkand.imeri/why-use-weakmaps-in-javascript-ea606974149d?source=rss-202785ebef11------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea606974149d</guid>
            <category><![CDATA[javascript-map]]></category>
            <category><![CDATA[weakmaps]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Erkand Imeri]]></dc:creator>
            <pubDate>Sat, 04 Nov 2023 15:41:35 GMT</pubDate>
            <atom:updated>2023-11-04T15:48:18.720Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9IDQqOgC2tJV5DOBV3-qnA.jpeg" /><figcaption><a href="https://unsplash.com/photos/person-writing-on-white-paper-ZWD3Dx6aUJg">https://unsplash.com/photos/person-writing-on-white-paper-ZWD3Dx6aUJg</a></figcaption></figure><p>Although WeakMap have been around for a time in JavaScript usually we ignore the actual usage of why this particular data structure comes handy for us. Well, that’s something which i have been wondering lately.</p><p>But first let us just have a quick overview of Map and the particular scenario with Map which might cause issues and how WeakMap comes to help.</p><h3>Maps in JavaScript</h3><p>The Map in JavaScript, not to be confused with the Array prototype method map() was introduced in JavaScript ES6 as a new collection type of key-value pair, that acts as a more advanced and sophisticated key-value mapper than literal objects.</p><p>Technically, the difference between the map and the literal object {} is that the Map as keys is not limited only with String and Symbol, but it can contain also functions and objects.</p><p>Below we will start with some basic operations for Map.</p><pre>const users = new Map([<br>  [&#39;user1&#39;, { name: &#39;John&#39;, age: 30, email: &#39;john@example.com&#39; }],<br>  [&#39;user2&#39;, { name: &#39;Bob&#39;, age: 25, email: &#39;bob@example.com&#39; }],<br>  [&#39;user3&#39;, { name: &#39;Luke&#39;, age: 35, email: &#39;luke@example.com&#39; }]<br>]);<br><br>// Output: { name: &#39;Bob&#39;, age: 25, email: &#39;bob@example.com&#39; }<br>console.log(users.get(&#39;user2&#39;));<br><br>// Iterating over the Map<br>for (let [userId, userInfo] of users) {<br>  console.log(`User ID: ${userId}, Name: ${userInfo.name}, Age: ${userInfo.age}`);<br>}<br><br>// Adding a new user<br>users.set(&#39;user4&#39;, { name: &#39;Dave&#39;, age: 40, email: &#39;dave@example.com&#39; });<br><br>// Removing a user<br>users.delete(&#39;user1&#39;);<br><br>// Checking the number of users<br>// Output: 3 (&#39;user1&#39; has been deleted)<br>console.log(users.size); </pre><p>Now, let’s explore the statement of why Map introduced the possibility of using functions and objects as keys in a mapper.</p><pre>const eventHandlers = new Map();<br><br>function registerEventHandler(event, handler) {<br>  if (!eventHandlers.has(handler)) {<br>    // Use a function as key in a Map<br>    eventHandlers.set(handler, event);<br>    // Attach event...<br>  }<br>}<br><br>function unregisterEventHandler(handler) {<br>  if (eventHandlers.has(handler)) {<br>    // Detach event...<br>    eventHandlers.delete(handler);<br>  }<br>}<br><br>const resultCache = new Map();<br><br>function memoizedFunction(obj) {<br>  if (resultCache.has(obj)) {<br>    return resultCache.get(obj);<br>  }<br>  // Compute the result<br>  const result = expensiveComputation(obj);<br>  // Use obj as key in a Map<br>  resultCache.set(obj, result);<br>  return result;<br>}</pre><p>As we see from above, using functions or objects as keys in Map is a powerful concept which brings a lot of flexibility and power but we need to be careful since a Map holds strong references to its keys, it can prevent those keys from being garbage-collected, potentially leading to memory leaks if not managed correctly. It’s important to remove entries when they are no longer needed, especially in long-lived Maps.</p><pre>// Creating separate user objects<br>let user1 = { name: &#39;John&#39;, email: &#39;john@example.com&#39; };<br>let user2 = { name: &#39;Bob&#39;, email: &#39;bob@example.com&#39; };<br>let user3 = { name: &#39;Luke&#39;, email: &#39;luke@example.com&#39; };<br><br>// Creating a Map with explicit references to user objects<br>let userReference = new Map();<br>userReference.set(user1, &#39;user1 Reference&#39;);<br>userReference.set(user2, &#39;user2 Reference&#39;);<br>userReference.set(user3, &#39;user3 Reference&#39;);<br><br>// Now if you no longer need user3, you remove it from the map<br>user3 = null;<br><br>// userReference will continue holding `user3 Reference` <br>// despite user3 being assigned to null, garbage collector will ignore until<br>// you delete from the Map explicitly<br>console.log(userReference);</pre><p>Now, this for small amount of objects will not make a difference for sure, but imagine if we had in hundreds of thousands, for sure we will have a memory leak in our application.</p><h3>WeakMaps into the play</h3><p>So, here is where WeakMap come in consideration, the Weak prefix to Map instigate that it has a weak reference to the object and function keys. And yes, WeakMap can contain only functions and objects (arrays are fundamentally objects in JavaScript) as keys.</p><p>Now, let’s try the previous example with WeakMap</p><pre>// Creating separate user objects<br>let user1 = { name: &#39;John&#39;, email: &#39;john@example.com&#39; };<br>let user2 = { name: &#39;Bob&#39;, email: &#39;bob@example.com&#39; };<br>let user3 = { name: &#39;Luke&#39;, email: &#39;luke@example.com&#39; };<br><br>// Creating a WeakMap with explicit references to user objects<br>let userReference = new WeakMap();<br>userReference.set(user1, &#39;user1 Reference&#39;);<br>userReference.set(user2, &#39;user2 Reference&#39;);<br>userReference.set(user3, &#39;user3 Reference&#39;);<br><br>// Now if you no longer need user3, you set it to null<br>user3 = null;<br><br>// The user3 entry will be cleared when the garbage collector runs,<br>// which cannot be determined or forced in JavaScript.<br>// userReference then will hold 2 values</pre><p>So WeakMap with its weak references to the keys, allow us to write code and not worry about explicitly removing Map references when we delete or empty a user object.</p><h3>Conclusion</h3><p>In conclusion, while Map offers us a robust way to associate data with objects and functions, we must tread carefully to avoid memory leaks. WeakMap comes in as the unsung hero for certain use cases where associations should be ephemeral, not hindering garbage collection. They ensure that once objects go out of scope, they—and their related data—can be cleaned up, keeping our applications efficient and memory-friendly. Whether you&#39;re managing event handlers, caching results, or just keeping track of miscellaneous metadata, WeakMap is an excellent tool for maintaining these relationships without compromising on performance. Embrace WeakMap when you need that automatic memory management superpower in your JavaScript toolbox.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea606974149d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>