<?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 Daily JavaScript on Medium]]></title>
        <description><![CDATA[Stories by Daily JavaScript on Medium]]></description>
        <link>https://medium.com/@daily_javascript?source=rss-aa7887aaf4b3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ROSds5vCDt3cFkDdynHqhA.png</url>
            <title>Stories by Daily JavaScript on Medium</title>
            <link>https://medium.com/@daily_javascript?source=rss-aa7887aaf4b3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 20:04:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@daily_javascript/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[A Friendly Guide to Big O]]></title>
            <link>https://medium.com/@daily_javascript/a-friendly-guide-to-big-o-ea781c5f68f0?source=rss-aa7887aaf4b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea781c5f68f0</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Daily JavaScript]]></dc:creator>
            <pubDate>Sun, 03 Mar 2019 16:11:59 GMT</pubDate>
            <atom:updated>2019-03-03T16:30:11.486Z</atom:updated>
            <content:encoded><![CDATA[<h3>Daily JavaScript</h3><p>Sun, Mar 3, 2019</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*AB61St1Tu6J_JJmkAYsyRw.png" /></figure><p>Not every tech company will ask you questions related to Big O when interviewing, but it is one of the concepts that you need to know if you want to work at a place like Amazon or Facebook. The textbook definition of Big O is absolutely terrifying to someone without a deep understanding of math.</p><pre>Let T(n) = the number of operations performed in an algorithm as a function of n. </pre><pre>T(n) = O(f(n)) if and only if there exists two constants, n0 &gt; 0 and c &gt; 0, and a function f(n) such that for all n &gt; n0, cf(n) ≥ T(n).</pre><p>Yikes, ok let’s brush up on mathematical proofs. Just kidding, the actual concept is a lot less complex than the formal definition would indicate.</p><p>Have you ever had to do some task, and in order to accomplish it, you have to follow a series of steps?</p><p>Essentially that’s an algorithm in computer science — a series of steps.</p><p>When completing a task in real life, sometimes there’s better ways of doing it — faster, cheaper, less messy, etc. The same is true about algorithms. There’s better ways of implementing algorithms. But how would we calculate what is a better algorithm for computers and what does better mean?</p><p>One intuitive way of calculating which algorithm is better is to choose the one that completes the task in the fastest amount of time — often called runtime. Unfortunately, it’s difficult to compare the precise speed of an algorithm in real life because it is influenced by a lot of factors unrelated to the algorithm itself. The language you choose to write the algorithm in, the version of the language you choose to write the algorithm in, the hardware of the computer and the input size of the data all have an effect on how fast the algorithm gets completed. So what we can do is approximate the runtime by comparing how many steps an algorithm takes from when it begins to when it is finished and use the total number of steps as an approximation for time. We should agree to some assumptions that hold true regardless of machine or language used so everyone has a common way to compare two different algorithms that solve a problem.</p><p><strong>Assumption 1:</strong></p><ul><li>Each of the steps are read by the computer one at a time in order from top to bottom.</li></ul><p><strong>Assumption 2:</strong></p><ul><li>Assigning to a variable, calling on a function, logic comparisons and any arithmetic operation (e.g. +, — *, /) all take one step.</li></ul><p><strong>Assumption 3:</strong></p><ul><li>Memory is infinite and accessing data stored anywhere in memory takes the same amount of time.</li></ul><p>Let’s look at a quick example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eGTaojz9V8ZpTdTKAuPuFg.png" /></figure><p>So this algorithm begins with an assignment, which is one step. Then it goes in to a while loop, which is 3 steps, and finally returns the variable, which is one step. So we can write this as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DMdKEG8teNpyqOESq61o1w.png" /></figure><p>If b is 100, the algorithm has 302 steps.</p><p>If b is 1000, then it has 3002 steps.</p><p>And finally, if b is 10,000, then the algorithm has 30,002 steps.</p><p>As you can see, in terms of comparing, since we don’t have to be exact, the 2 digit in the ones’ column really doesn’t make a huge difference in helping us compare. That’s why, when calculating Big O, you only really care about the factors that make the biggest difference in the calculation and can safely ignore constants and lower order terms, a lower order term being a value that is an order of a magnitude less. So for example, in</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zonDOqqgxsAzRtfl9dvR9w.png" /></figure><p>you can safely ignore x and x², since they won’t make as big of a difference in your estimation as x³.</p><p>Big O is really just about judging the rate of growth of the runtime, otherwise known as Asymptotic Analysis.</p><p>So, we have a rough idea of how to calculate Big 0 but how do we know what input to choose for comparison? We want to choose a large enough input that let’s us ignore the constant and lower order term values. In particular, Big O is concerned with the worst-case scenario for size of the input, mostly because that’s the most interesting comparison case.</p><p>Interestingly enough it turns out that most algorithms fall under one of a few common categories and I will talk more about those in the next blog article.</p><blockquote><strong><em>If you found this article interesting or would love to become a better programmer, consider signing up at </em></strong><a href="https://www.dailyjavascript.io/?refcode=551210dea652efaf63bb"><strong><em>Daily JavaScript</em></strong></a><strong><em> to get daily javascript challenges, code snippets and articles.</em></strong></blockquote><p><em>Originally published at </em><a href="https://dailyjavascriptblog.netlify.com/posts/a-friendly-guide-to-big-o?refcode=551210dea652efaf63bb"><em>dailyjavascriptblog.netlify.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea781c5f68f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is strict mode and should you enable it when writing JavaScript?]]></title>
            <link>https://medium.com/@daily_javascript/what-is-strict-mode-and-should-you-enable-it-when-writing-javascript-e05f3c159d47?source=rss-aa7887aaf4b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/e05f3c159d47</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Daily JavaScript]]></dc:creator>
            <pubDate>Tue, 11 Dec 2018 21:59:16 GMT</pubDate>
            <atom:updated>2018-12-11T21:59:16.578Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*K-luBpaN0_XDxPKong5vMA.jpeg" /></figure><h3>Daily JavaScript</h3><p>Tue, Nov 20, 2018</p><p>A few of our users at <a href="https://www.dailyjavascript.io/?refcode=f0e0249dbfd0e3570bc3"><strong>Daily JavaScript</strong></a> have emailed me asking if they should enable strict mode when writing the solution to the daily javascript coding challenges. I decided to write a post to clarify to all our users what strict mode is and if there is any benefits to enabling it when writing their coding solutions.</p><h3>TL;DR</h3><blockquote><strong><em>JavaScript lets you declare ‘strict mode’ in your JavaScript files to remove some of the flexibility innate in the JavaScript language prior to ES5. It’s not required for solving the coding challenges and no company is going to think poorly of you if you neglect to include it in your solutions when you are given a coding challenge or whiteboard problem during a technical interview.</em></strong></blockquote><p>With that out of the way, let’s dive into what strict mode is and how we would enable it.</p><p>Strict Mode was a feature introduced in ES5. When you enable it, the JavaScript runtime prevents certain code that’s considered bad practice from being executed and throws exceptions instead of silently failing.</p><p>So why is this good?</p><p>JavaScript is designed to be easy for developers to write and execute code. Compared to say Haskell or Java, JavaScript developers do not have to worry about compiling their code or writing types. So if you’re a novice JavaScript developer, you could get a program set up and working pretty fast. This speed though has some drawbacks in that some of the code written can contain bugs that affect the program much later on as the complexity of the program increases. With strict mode enabled, some classification of bugs are caught much earlier and can be fixed by the developer before it affects the program. Three common beginner JavaScript developer bugs restricted with strict mode:</p><ol><li>Strict mode makes it impossible to accidentally create global variables</li></ol><pre>function notStrictModeEnabled() { <br>  x = 17 <br>}; </pre><pre>notStrictModeEnabled() //no errors</pre><pre>function strictModeEnabled() { <br>  &#39;use strict&#39; x = 17 <br>}; </pre><pre>strictModeEnabled() //errors</pre><p>2. Strict mode makes assignments which would otherwise silently fail to throw an exception.</p><pre>function notStrictModeEnabled() { <br>  Infinity = 17 <br>}; </pre><pre>notStrictModeEnabled() //no errors</pre><pre>function strictModeEnabled() { <br>  &#39;use strict&#39; <br>  Infinity = 17 <br>}; </pre><pre>strictModeEnabled() //errors</pre><p>3. Strict mode requires that function parameter names be unique.</p><pre>function notUniqueParamsInFunction(a, a, c) { <br>  &#39;use strict&#39;; <br>  return a + a + c;  // errors <br>}</pre><p>There are many more restrictions that strict mode introduces that you can read about in the official standards on page 235: <a href="http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf">ECMA Language Specification</a> or you can check out <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode">MDN</a> Strict Mode article for a more readable experience</p><p>Cool! So how do I enable this in my code?</p><p>There are four ways to enable ‘strict mode’:</p><ol><li>You include it at the top of your file or script tag.</li></ol><pre>&#39;use strict&#39;; <br>//...rest of your file</pre><p>or</p><pre>&lt;script&gt; <br>  `use strict` <br>  // ...rest of your code <br>&lt;/script&gt;</pre><p>2. You can include it at the top of your function declaration or function expression.</p><pre>function strictModeEnabledFunctionDeclaration(){ <br>  &#39;use strict&#39;; <br>  //...rest of your code;  <br>} </pre><pre>var strictModeEnabledFunctionExpression = function() { <br>  &#39;use strict&#39;; <br>  //...rest of your code;  <br>}</pre><p>3. Your code is automatically in strict mode if you export it as a module.</p><pre>function strictModule() { <br>  // because this is a module, I&#39;m strict by default <br>} </pre><pre>export default strictModule;</pre><p>4. Use babel. In Babel 6, transformations for ES6 modules ran on whatever files it was told to process, never taking into account if the file actually had ES6 imports/exports in them. This had the effect of inserting “use strict” at the top of all modules that were processed by Babel. In Babel 7, you would have to enable this behavior by using transform-strict-mode plugin.</p><p>There are other benefits to using strict mode that I didn’t mention in this post that you can read about more in the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode">MDN</a> Strict Mode article mentioned above. These include code optimization by the JavaScript engine in browsers, more secure JavaScript code and restricting namespaces for future JavaScript features. Some big companies currently using strict mode in production include Facebook and Google.</p><blockquote><strong><em>If you found this article interesting or would love to become a better programmer, consider signing up for free at </em></strong><a href="https://www.dailyjavascript.io/?refcode=f0e0249dbfd0e3570bc3"><strong><em>Daily JavaScript</em></strong></a><strong><em> to get daily javascript challenges, code snippets and articles.</em></strong></blockquote><p><em>Originally published at </em><a href="https://dailyjavascriptblog.netlify.com/?refcode=f0e0249dbfd0e3570bc3"><em>dailyjavascriptblog.netlify.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e05f3c159d47" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>