<?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 Sam Brozinsky on Medium]]></title>
        <description><![CDATA[Stories by Sam Brozinsky on Medium]]></description>
        <link>https://medium.com/@s77broz?source=rss-87e452264202------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*rE0foDqumJaHF82t.</url>
            <title>Stories by Sam Brozinsky on Medium</title>
            <link>https://medium.com/@s77broz?source=rss-87e452264202------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 19:27:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@s77broz/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[On JavaScript’s Quirks]]></title>
            <link>https://medium.com/@s77broz/on-javascripts-quirks-504591559826?source=rss-87e452264202------2</link>
            <guid isPermaLink="false">https://medium.com/p/504591559826</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Sam Brozinsky]]></dc:creator>
            <pubDate>Thu, 17 Jan 2019 15:39:13 GMT</pubDate>
            <atom:updated>2019-01-17T15:39:13.935Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*sUsgwQFLOaseXWlAO6t4tg.jpeg" /></figure><h4><strong>Automatic Semicolon Insertion (ASI)</strong></h4><p>If you are familiar with the syntax of JavaScript, then you are likely aware that your code does not require semicolons. This is due to an implementation detail known as Automatic Semicolon Insertion, or ASI.</p><p>While ASI is generally good at determining where to put semicolons, it can within certain circumstances deem something that truly needs a semicolon does not need one.</p><p>As an example of this, the following code will throw an error, saying that b is not a function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/feca44db0de3ebaa7b23062323e848cc/href">https://medium.com/media/feca44db0de3ebaa7b23062323e848cc/href</a></iframe><p>And the reason that this errors, is because ASI will read it as this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d3683f59aacd756d32c60666a532a9a4/href">https://medium.com/media/d3683f59aacd756d32c60666a532a9a4/href</a></iframe><p>Which is deemed valid JavaScript, and so it won’t insert a semicolon.</p><h4>HTML Style Comments</h4><p>Many years ago, some browsers didn’t support script tags. To counteract this, HTML stylized single line comments were implemented.</p><p>Opening HTML style comments (&lt;!--) can be used anywhere and will act as a normal single line comment.</p><p>Closing HTML style comments (--&gt;) must be the first non-whitespace character of a line, otherwise it will be interpreted as normal JS.</p><p>With this knowledge, what do you think the following code returns?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fdf6c3d2fb6ab28366c63239d909ace0/href">https://medium.com/media/fdf6c3d2fb6ab28366c63239d909ace0/href</a></iframe><h4>Abstract Equality Comparison Type Conversions</h4><p>When doing an abstract equality comparison (==), JavaScript will do certain type conversions in a specific order, until it returns false or can perform a strict equality comparison.</p><p>Knowing the following order can help when figuring out why certain things are not running as you’d expect:</p><ul><li>If the types are the same, perform a strict equality comparison</li><li>If one is null and one is undefined, return true</li><li>If one is a number and one is a string, return the result of the comparison number == ToNumber(string)</li><li>If one is a Boolean, return the result of the comparison otherVal == ToNumber(Boolean)</li><li>If one is a String, Number, or Symbol, and the other is an Object, return the result of the comparison val == ToPrimitive(Object)</li><li>Return false</li></ul><p><a href="https://www.ecma-international.org/ecma-262/9.0/index.html#sec-abstract-equality-comparison">ECMAScript® 2018 Language Specification</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=504591559826" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[All the Promises!]]></title>
            <link>https://medium.com/@s77broz/all-the-promises-d17c36a3678b?source=rss-87e452264202------2</link>
            <guid isPermaLink="false">https://medium.com/p/d17c36a3678b</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Sam Brozinsky]]></dc:creator>
            <pubDate>Mon, 07 Jan 2019 16:30:22 GMT</pubDate>
            <atom:updated>2019-01-07T16:30:22.763Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*78_2saNBD-eG5Vwj.jpg" /></figure><p>So you’re working with promises, and you came across a new problem: you need the value of several promises before you can run a section of your code. To do this normally, you’d have to use something like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5198e6e7390e7412d1673bcd3ad547c4/href">https://medium.com/media/5198e6e7390e7412d1673bcd3ad547c4/href</a></iframe><p>With this you might as well be using normal callbacks! So how could we make this better?</p><p>Enter: Promise.all</p><p>Promise.all is a helpful function on the Promise class that lets us resolve with several values at once. It accepts an array of Promises, and resolves with the resolved values of each Promise matching its position in the provided array.</p><p>Modifying the above example, it can be rewritten as:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e6c4a3b989a8d4d3a52569ae7cd892f2/href">https://medium.com/media/e6c4a3b989a8d4d3a52569ae7cd892f2/href</a></iframe><p>This makes our code far cleaner, and much more readable.</p><p>As an example, say you have an API to find the syllable count of a word, and you want to sum the syllable count of a sentence. You have to make a separate request for each word, but you can’t sum the count until you have everything ready.</p><p>First, you have to make all the requests to the API:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a357735b4d2505c6c58c45409e46a71/href">https://medium.com/media/9a357735b4d2505c6c58c45409e46a71/href</a></iframe><p>Then, you use Promise.all to get all the values and sum the syllable count:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50de39236e55fb5193ffc831a4538787/href">https://medium.com/media/50de39236e55fb5193ffc831a4538787/href</a></iframe><p>This resolves with All the word info objects, and reduces them with a number accumulator starting at zero, adding the syllableCount value from the resolved object.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d17c36a3678b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making an API with Express.js]]></title>
            <link>https://medium.com/@s77broz/making-an-api-with-express-js-dcfc5feefd64?source=rss-87e452264202------2</link>
            <guid isPermaLink="false">https://medium.com/p/dcfc5feefd64</guid>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Sam Brozinsky]]></dc:creator>
            <pubDate>Wed, 12 Dec 2018 14:41:07 GMT</pubDate>
            <atom:updated>2018-12-13T18:48:50.187Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*XgB-Sjd4ZuwQgvxLijnnDw.gif" /><figcaption>What it’s like to write an API for the first time</figcaption></figure><p>With making a web app, you may need an API to allow communicate with your backend. There are several ways to go about this, and with Node.js, the most common way is to use a package called Express.</p><p>Express is, at its core, a routing engine, letting you easily define any routes you may need for your app.</p><p>To install express, assuming you already have node installed, is as simple as:</p><pre>npm i express</pre><p>With express installed, you can start making your API!</p><p>To make a simple API, you only need a few lines of code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc38330ad42ef7776df05e211ace545d/href">https://medium.com/media/bc38330ad42ef7776df05e211ace545d/href</a></iframe><p>This code makes a very basic server which, while active, will send the text “Hello World!” when you do GET /.</p><p>Adding further routes is simple, and supports utilizing dynamic routes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/326e178f38d61cf81e297dbc54e49233/href">https://medium.com/media/326e178f38d61cf81e297dbc54e49233/href</a></iframe><p>And now we can do GET /rooms/32, and see the appropriate response!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Npxd1qXzBUSXskskgdMgUQ.png" /></figure><p>Typically when making an API, we want to send back a JSON string, rather than plaintext or HTML. Doing this in JavaScript is quite simple! In any environment, the JSON global object will be available, letting you add a route as such:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f9f1765ed090dd7085ce79f73d736a1/href">https://medium.com/media/7f9f1765ed090dd7085ce79f73d736a1/href</a></iframe><p>And now, we can GET /rooms/32/messages/44, and see the appropriate message JSON!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d4ZLCz11ZZgJj0gan3kbuQ.png" /></figure><p>Expanding this to utilize a database is as easy as installing your preferred driver, and doing any normal operations required to set it up.</p><p><a href="https://expressjs.com/">Express - Node.js web application framework</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dcfc5feefd64" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Promises and Async: The Future Awaits]]></title>
            <link>https://medium.com/@s77broz/promises-and-async-the-future-awaits-671179ab3fa9?source=rss-87e452264202------2</link>
            <guid isPermaLink="false">https://medium.com/p/671179ab3fa9</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Sam Brozinsky]]></dc:creator>
            <pubDate>Wed, 28 Nov 2018 14:40:50 GMT</pubDate>
            <atom:updated>2018-11-28T16:08:51.538Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*BZpeuHLNLisAJ5mp.gif" /></figure><p>Let’s say you want to watch a movie. There’s no stream available, so you have to download it. That can take a lot of time, right? So why would you stop everything and wait for that to finish?</p><p>That same principle applies to code. Sometimes you make a request, and those requests can take time to process. But what if there are other tasks that need to be handled, that don’t require the data from the request? Enter: asynchronous code.</p><p>Say you have a website that displays every anime. That’s a lot of information to retrieve! It can definitely take some time, so why have your code sit around doing nothing while the data is sent? There are many other things that aren’t dependent on that information your site handles. With asynchronous code, you can have the anime information request running at the same time as other tasks.</p><p>In JavaScript, this used to be handled entirely through callbacks. Callbacks are simply functions passed as an argument to another function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LhWKGunpT5YsiDJ4Sw7SaA.png" /></figure><p>This is what that can end up looking like. It’s several levels deep, unreadable, and has to handle the error in each individual callback. This is known as callback hell.</p><p>This is where ES6 comes in: Promises.</p><p>A Promise is a type of object that allows you to more cleanly handle asynchronous tasks. They still use callbacks, but it ends up far more readable and more easily maintained.</p><p>The above code, revised to use promises, would look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iCSA6zs6GebQdDunr2jGaQ.png" /></figure><p>As you can see, the code is shorter, clearer, and only needs to handle the error once!</p><p>There are a few caveats to how Promises work, though:</p><ul><li>Normal error handling (try/catch) will NOT catch Promise errors</li><li>Values inside the callback passed to Promise#then CAN NOT be accessed outside of it.</li></ul><p>So what if you need values from the Promise further down the line? Well, we can refactor the code even further, using ES7 Async/Await!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iGVrlHTJHJmd5f1KmRaBag.png" /></figure><p>It may be slightly longer than using Promises, but as you can see, it doesn’t have any callbacks, and normal error handling will catch awaited promises that error!</p><p>The keyword await will only work within functions declared as async.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=671179ab3fa9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Utilizing Git (and Using it Effectively)]]></title>
            <link>https://medium.com/@s77broz/utilizing-git-and-using-it-effectively-4d4a7d8fe3fc?source=rss-87e452264202------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d4a7d8fe3fc</guid>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Sam Brozinsky]]></dc:creator>
            <pubDate>Wed, 14 Nov 2018 16:47:56 GMT</pubDate>
            <atom:updated>2018-11-14T16:47:56.394Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*-ty9Xif-xq8b3j4JxfIprQ.gif" /><figcaption>A potential consequence of not having version control</figcaption></figure><p>In the realm of programming, git has become a central part of workflow. But what exactly is git? And how does one use it properly?</p><p>Git is a type of version control. It lets you keep track of changes, manage additions of various features, and keeps your work well organized.</p><p>To master git requires knowledge of its best practices, and there are several to learn:</p><ul><li>best commit messages</li><li>keeping commits simple</li><li>keeping master deployable</li><li>keeping branches simple</li></ul><p>To start with, commit messages should always follow the imperative present tense. To make it easy to remember, your message should complete the sentence “This commit will”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*AVRncf3mpAWTk2rH5_fpjA.png" /><figcaption>A commit following the imperative tense</figcaption></figure><p>Commit messages should also be kept short. A good rule of thumb is no more than 50 characters in length. They should succinctly describe what has been changed since the last commit. If a commit message cannot be written as such, summarize the goal of the commit, and include a commit description. Each line of the description should be word wrapped at around 72 characters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5kLBnPYNGGNjxtBcPdKEBA.png" /><figcaption>A well formed commit with description</figcaption></figure><p>Commits should be made frequently, the code should not be half-done work, and the code should actually do what is intended. Rather than working on a single, large method, break it into smaller methods that can be committed individually. A general rule of thumb for time between commits is 5–7 minutes of work.</p><p>Features should be added by branching off of master, then merging it back in once complete. The standard practice for git is that the master branch should <em>always</em> be deployable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*Tt_WPCcEVF4YqJGn9zOoKg.png" /><figcaption>An example of a well named branch</figcaption></figure><p>For additional information on best practices, see: <a href="https://github.com/trein/dev-best-practices/wiki/Git-Commit-Best-Practices">https://github.com/trein/dev-best-practices/wiki/Git-Commit-Best-Practices</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d4a7d8fe3fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>