<?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 Will Brickner on Medium]]></title>
        <description><![CDATA[Stories by Will Brickner on Medium]]></description>
        <link>https://medium.com/@willbrickner?source=rss-eb5bab74a2ec------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1AhLLDUXSi2dtjolVoEKGg.jpeg</url>
            <title>Stories by Will Brickner on Medium</title>
            <link>https://medium.com/@willbrickner?source=rss-eb5bab74a2ec------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 09:58:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@willbrickner/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[6 quirks & tricks all JavaScript developers should know]]></title>
            <link>https://medium.com/@willbrickner/6-quirks-tricks-all-javascript-developers-should-know-d1cf247be6b4?source=rss-eb5bab74a2ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1cf247be6b4</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Will Brickner]]></dc:creator>
            <pubDate>Mon, 21 May 2018 01:07:23 GMT</pubDate>
            <atom:updated>2018-05-21T02:27:52.504Z</atom:updated>
            <content:encoded><![CDATA[<p>A collection of tricks to write interesting, safe code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xxVDmlhE8xH6wONzfathxg.jpeg" /></figure><h4>Objects are assigned by reference</h4><p>This is critically important. Without understanding this you can go quite far, but you will eventually get yourself into very big trouble unless you know how to handle objects properly.</p><p>Let’s take a look at the following example code:</p><pre>var carA = { nice: true }<br>var carB = carA</pre><p>You may expect carB to be a separate copy of carA. In JavaScript, this is not the case.</p><p>If you change carA, the changes are immediately reflected in the value of carB:</p><pre>carA.nice = false<br>console.log(carB) // { nice: false }</pre><p>And vice-versa:</p><pre>carB.nice = “string-cheese”<br>console.log(carA) // { nice: “string-cheese” }</pre><p>You should think of carB and carA as nicknames, both actually referencing the same object.</p><h4>Properties of ‘constant’ objects are actually mutable</h4><p>Let’s take a look at the following code:</p><pre>const winner = { name: “Jerry Smith” }</pre><p>You might think that because we declared the variable as a constant, it’s value (e.g. it’s properties) cannot be changed.</p><p>As you can see, this is not true:</p><pre>winner.name = “Will”<br>console.log(winner) // { name: “Will” }</pre><p>No exception is thrown.</p><p>You cannot count on properties remaining constant simply because the object was declared as a constant.</p><h4>Functions are first-class objects</h4><p>Let’s say I define a little function:</p><pre>function doThing(n) { … }</pre><p>One can actually store data (and other functions) as a property on the function itself:</p><pre>doThing.myFavoriteNumber = -1/12<br>doThing.myFunction = function (m) { … }</pre><pre>doThing() // still works like a regular function<br>Object.keys(doThing) // [ “myFavoriteNumber”, “myFunction” ]</pre><h4>All objects have a `valueOf` method</h4><p>If you know how to use it, you can pull off some very interesting tricks in JavaScript:</p><pre>function coefficient(x) { return 1 + Math.sqrt(x / 2) }<br>coefficient.valueOf = () =&gt; 1</pre><p>Now, look how I can choose to use coefficient:</p><pre>var a = 1/137<br>var myValue = a * coefficient(10.0) // = (1/137) * (1 + sqrt(5))</pre><p>I’ve also built in a hidden default value:</p><pre>var myValue = a * coefficient // = (1/137) * (1)</pre><h4>Symbols</h4><pre>var fruit = { <br>  name: &quot;Apple&quot;, <br>  color: &quot;Red&quot;,<br>  eat: () =&gt; { console.log(&quot;existing&quot;) }<br>}</pre><p>What if you want a new function you can access, which in your code you can call eat , but you can’t overwrite the existing function eat ?</p><p>Symbols to the rescue:</p><pre>const eat = Symbol.from(&quot;eat&quot;)<br>fruit[eat] = () =&gt; { console.log(&quot;new&quot;) }</pre><p>And now we can access the value using the symbol:</p><pre>fruit[&quot;eat&quot;]() // logs: &quot;existing&quot;<br>fruit[eat]()   // logs: &quot;new&quot;</pre><h4>All objects have a `toString` method</h4><pre>var writer = { name: &quot;Will&quot; }<br>writer.toString = function () { return this.name }<br>console.log(writer + &quot; wrote on medium!&quot;) // Will wrote on medium!</pre><h3>There are many more interesting facets of JavaScript which aren’t included</h3><p>The best method of becoming familiar with the many beautiful peculiarities of the language is to <strong>simply spend time with it</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1cf247be6b4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>