<?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 Edmund Ekott on Medium]]></title>
        <description><![CDATA[Stories by Edmund Ekott on Medium]]></description>
        <link>https://medium.com/@26th-edmund?source=rss-7f156d83daa1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*R8CReyCeFqDLhFL-mrqGHw.jpeg</url>
            <title>Stories by Edmund Ekott on Medium</title>
            <link>https://medium.com/@26th-edmund?source=rss-7f156d83daa1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 13:58:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@26th-edmund/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[What Is This “Strict Mode”?]]></title>
            <link>https://medium.com/better-programming/what-is-this-strict-mode-4879143b46a?source=rss-7f156d83daa1------2</link>
            <guid isPermaLink="false">https://medium.com/p/4879143b46a</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[strict-mode]]></category>
            <dc:creator><![CDATA[Edmund Ekott]]></dc:creator>
            <pubDate>Wed, 10 Jul 2019 01:00:39 GMT</pubDate>
            <atom:updated>2019-07-12T11:38:28.965Z</atom:updated>
            <content:encoded><![CDATA[<p>As a JavaScript developer, it’s possible that you might have used strict mode at one point or the other in your code and if you haven’t, well, you might someday. Strict mode can be helpful when trying to debug your app because it brings up errors that you normally wouldn’t expect in sloppy mode (more on that later), the opposite of strict mode, so let’s get to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*cQ9TmWqBa02wb9GK4tYt3g.png" /></figure><h3>What Is Strict Mode?</h3><p>First introduced in the <a href="https://en.wikipedia.org/wiki/ECMAScript">ECMAScript</a> version 5, strict mode is a way of ensuring our code doesn’t have any loose ends. It ensures that your code is free of errors as much as possible.</p><h3>What Does It Do?</h3><ul><li>Strict mode converts silent errors to throw errors. What that means is that there are some errors in our code that JavaScript can let slide in order for our code to continue running. This is JavaScript being helpful and sometimes it might come with unforeseen consequences which lead to bugs in our apps.</li><li>Strict mode also prevents you from writing code in a particular way that is either risky or not a good practice at all.</li></ul><h3>How to Enable Strict Mode?</h3><p>Enabling strict mode is really easy; all you have to do is add &quot;use strict&quot;; to the top of your code and you’re all set. Let&#39;s look at some examples below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*peyhxT9AS505J64cWAn1cQ.png" /></figure><p>Taking a look at the code snippet above, how do you think the variable initialized without the var, let or const keyword should be handled? anotherVariable was never declared as a variable and line 5 is trying to modify a variable called anotherVariable. It makes sense for the browser to throw an error because anotherVariable does not exist; it was never declared before trying to modify it. But what if we remove the &quot;use strict&quot;; statement?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1cvHE1aqNH_NhKdxZ9gAlg.png" /></figure><p>Looking at the snippet above and reading the comments above you could tell what’s happening there. In non-strict mode, or “sloppy mode,” the undeclared variable gets attached to the global window object. JavaScript saw that the variable never existed before and now tries to help us by adding it as a property to the window object so we can access it as a global variable. This is not really a good idea because if some library you import has a variable with that same name there’s going to be a problem because referencing that variable now might just go fetch whatever you put up in the global window object as the value.</p><h3>Limiting Strict Mode to a Scope</h3><p>That’s right, you can limit strict mode to only a block of code if you like. Say you wanted to be sure about what’s getting returned from a function call so the value doesn’t break your code; limiting strict mode to that local scope is the way to go. So basically strict mode can either be in the global scope or in a local scope (within two curly braces).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*RoC_JlUjUFX4WvsyH4KWQw.png" /></figure><p>The snippet above differentiates the global scope from the local scope.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tHUPO5a-T26jazSDOO4tGA.png" /></figure><p>Now that we set the scope of the function doSomething() to run in strict mode, making a call to that function will cause our code to fail because anotherVariable was never declared before reassigning.</p><h3>What Else Can’t You Do in Strict Mode?</h3><ul><li>You cannot delete a variable, function, or an object with the delete keyword.</li><li>You cannot have duplicate parameter names in a function.</li><li>You cannot have duplicate object properties.</li><li>You cannot write to read-only object properties.</li><li>The this keyword refers to the object that called the function and not the global window object.</li></ul><p>These are just a few of the common ones; in the links below you can learn more about strict mode and its applications.</p><h3><strong>Links to Resources</strong></h3><ul><li>Strict mode — <a href="https://www.w3schools.com/js/js_strict.asp">W3Schools</a></li><li>Strict mode — <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode">Mozilla Developer Network</a></li><li>A practical application of strict mode — <a href="https://medium.com/@26th_edmund/how-to-make-specific-object-properties-behave-like-constants-5277eddba5b0">How to make object properties behave like constants</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4879143b46a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/what-is-this-strict-mode-4879143b46a">What Is This “Strict Mode”?</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to make specific object properties behave like constants]]></title>
            <link>https://medium.com/weekly-webtips/how-to-make-specific-object-properties-behave-like-constants-5277eddba5b0?source=rss-7f156d83daa1------2</link>
            <guid isPermaLink="false">https://medium.com/p/5277eddba5b0</guid>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Edmund Ekott]]></dc:creator>
            <pubDate>Thu, 30 May 2019 15:24:54 GMT</pubDate>
            <atom:updated>2020-05-28T09:37:57.044Z</atom:updated>
            <content:encoded><![CDATA[<p>Ever wondered how to prevent your code from mutating object properties whose values should never change?</p><p>I know what you’re probably thinking, why not just use a const keyword to declare the object? well, doing it that way would only prevent the variable itself from being mutated and not the object properties, for example:</p><figure><img alt="mutating properties" src="https://cdn-images-1.medium.com/max/1024/1*iC2HZw-sRVLAKv2iaLbXKA.png" /></figure><p>One way we could achieve this is to use the Object.freeze() method, but that locks down the entire object and in some cases we might not want that to happen, Object.freeze() not only prevents the value of the properties from being changed, but it also prevents new properties from being added to the object, existing properties from being removed, and prevents its prototype from being changed.</p><h3>What is the best way to do it then?</h3><p>In my own opinion, the best way to lock down an object’s property is to use the Object.defineProperty() method, this method allows you a bit more flexibility by allowing you to customize certain attributes of the property.</p><figure><img alt="using object.defineproperty" src="https://cdn-images-1.medium.com/max/1024/1*eWKfpjPQvFxe9WvZRuwe_g.png" /></figure><p>After taking a look at the code snippet above, you might be confused about what’s happening there, why did it return 2? why was there no error? we’ll get to that in a minute, first off let me explain how the Object.defineProperty method works.</p><p>Object.defineProperty() takes in three arguments:</p><p>The first one is the name of the object.</p><p>The second is the property name you want to configure (this has to be a string) it must match the name of an existing property in the object, if it doesn’t then a new property will be created with that name and the configurations will be assigned to the property instead (whoa! another way to create properties in objects).</p><p>The last argument is the property descriptor (sometimes called attributes), this is usually an object with four keys, but I only chose to use three because the fourth was not needed in this case, the four keys that define the property are:</p><ul><li>value</li><li>enumerable</li><li>writable</li><li>configurable</li></ul><p><strong>value: </strong>remember when I mentioned using Object.defineProperty() to create a new property in an object? this attribute comes in handy such that we can use it to assign a value to the property if it doesn’t have one, we can also use it to change the value right before making it read-only (it all depends on the order you arrange the attributes in). This value can be any valid JavaScript value, a string, boolean, null, etc.</p><p><strong>enumerable:</strong> this takes a boolean as its value, what this does is configure the property to either show up when the object is enumerated (looped through for example) or not, if the value is false, the property will be invisible in loops and other forms of enumeration.</p><p><strong>writable:</strong> this either makes it possible to change the value of the property or not, its expected value is a boolean, and if a value of false is assigned to it, the property becomes immutable.</p><p><strong>configurable:</strong> this attribute makes it impossible to configure the property with the attributes listed above when it is set to false. all other configuration would not work when the property is set to not be configurable, and this makes sense when we do not want our property tampered with, this attribute basically locks down the object’s property from configurations.</p><h3>Now, back to the mystery code.</h3><p>Why was there no error when we attempted to change the value of the property?</p><p>Well, JavaScript does something in the background that we might not know about. It suppresses errors as much as possible so our code would continue to run, so our code will fail silently and we wouldn’t know about it, this sometimes is the reason for bugs in our apps.</p><h4>How do we solve this?</h4><p>With strict mode, basically using strict mode gives us all the errors in our code and forces us to write good code, I won’t be going deep into what strict mode is and how it works as that would take us off the scope of this article. Take a look at the snippet below:</p><figure><img alt="code example of object.defineproperty" src="https://cdn-images-1.medium.com/max/1024/1*39FxViVZE-0eGMOzjannAg.png" /></figure><p>Adding the line &quot;use strict&quot;; at the top of our code helps us know what is going on with our object.</p><p>Maybe my next article will be going deep into what strict mode is in JavaScript.</p><p>Here are a few resources to learn more about objects and how to manipulate them.</p><ul><li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze">Freezing objects</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty">Defining object properties</a></li><li>H<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor">ow to view the attributes of the property</a></li></ul><h4><strong>Follow me on </strong><a href="https://twitter.com/26th_edmund"><strong>Twitter</strong></a></h4><p><strong>Check out my </strong><a href="https://edmundekott.me/"><strong>website</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5277eddba5b0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/weekly-webtips/how-to-make-specific-object-properties-behave-like-constants-5277eddba5b0">How to make specific object properties behave like constants</a> was originally published in <a href="https://medium.com/weekly-webtips">Webtips</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>