<?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 Izuking Ogbodo on Medium]]></title>
        <description><![CDATA[Stories by Izuking Ogbodo on Medium]]></description>
        <link>https://medium.com/@matthiasogbodo?source=rss-706bd7fb1eb1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*F2uMJlzKee74ZXg8W87piA.jpeg</url>
            <title>Stories by Izuking Ogbodo on Medium</title>
            <link>https://medium.com/@matthiasogbodo?source=rss-706bd7fb1eb1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 02:29:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@matthiasogbodo/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[ES6 for busy developers]]></title>
            <link>https://medium.com/@matthiasogbodo/es6-for-busy-developers-a8513177c966?source=rss-706bd7fb1eb1------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8513177c966</guid>
            <category><![CDATA[es6-module]]></category>
            <category><![CDATA[es6-js]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[es6]]></category>
            <dc:creator><![CDATA[Izuking Ogbodo]]></dc:creator>
            <pubDate>Sun, 26 May 2019 18:35:17 GMT</pubDate>
            <atom:updated>2019-05-28T07:51:11.985Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g3JGD3I2DiqauhK2CTMLmw.jpeg" /></figure><p>Javascript ES6 came with huge updates and made developers to code less and achieve more. These awesome features of ES6 have transformed the way developers code and reason about javascript in general.</p><p>This story summarizes the key features of ES6 for those developers who have been busy and never had the chance to check out the released features of Javascript ES6.</p><p>But before we proceed, bellow is the list of key updates that ES6 brought to the table for javascript developers:</p><ol><li>Block-Scoped Constructs Const and Let</li><li>Default Parameters</li><li>Template Literals</li><li>Multi-line Strings</li><li>Destructuring Assignment</li><li>Enhanced Object Literals</li><li>Arrow Functions</li><li>Promises</li><li>Classes</li><li>Modules, Import, and export</li><li>Generators</li><li>Rest and Spread operator</li></ol><p>But before we continue, let’s have a quick look back on how far Javascript has made it to this point.:</p><ol><li>1995: JavaScript is born as LiveScript</li><li>1997: ECMAScript standard is established</li><li>1999: ES3 comes out and IE5 is all the rage</li><li>2000–2005: XMLHttpRequest, a.k.a. AJAX gains popularity in apps such as Outlook Web Access (2000) and Oddpost (2002), Gmail (2004) and Google Maps (2005).</li><li>2009: ES5 comes out (this is what most of us use now) with forEach, Object.keys, Object.create(especially for <a href="http://www.crockford.com/">Douglas Crockford</a>), and standard JSON</li><li>2015: ES6/ECMAScript2015 comes out; it has mostly syntactic sugar because people weren’t able to agree on anything more groundbreaking (ES7?)</li></ol><p>That’s it. let’s proceed into these juicy features of ES6, shall we?</p><h3>Block-Scoped Constructs Const and Let</h3><p>const are to be used when declaring a variable with the sole intention of only reading from. This feature will not allow intentional or unintentional re-assignment of value to the variable declared as const.let is the same as const in the sense that they both are blocked-scoped. however, let can be re-assigned and assume new values; hence making it <strong>mutable variable.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/987815de6b4fe990197e66993f6794bf/href">https://medium.com/media/987815de6b4fe990197e66993f6794bf/href</a></iframe><h3>Default Parameters</h3><p>If you have worked with PHP before, you usually use default parameters. These allow you to define a parameter in advance.</p><p>That’s what ES6 has made available for Javascript developers as well.</p><p>Here is how it’s done:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff519d84d9026dde785dfd3ed1826fe0/href">https://medium.com/media/ff519d84d9026dde785dfd3ed1826fe0/href</a></iframe><h3>Template Literals</h3><p>Before ES6, developers concatenate string literals using the (+) symbol. This can be a pain in the ass if you want to use some special characters like an apostrophe, quotation mark, etc in the string literal. But with the elegant ES6 string literals syntax, developers can add string literals in code at ease using the back-stick (``) symbol. look at this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c92e2ea79c6847f26f5d6f41f324658/href">https://medium.com/media/6c92e2ea79c6847f26f5d6f41f324658/href</a></iframe><h3>Multi-line Strings</h3><p>Another yummy syntactic sugar is a multi-line string syntax.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/834a55e4cf59ad11d92001e5c59855b4/href">https://medium.com/media/834a55e4cf59ad11d92001e5c59855b4/href</a></iframe><h3>Destructuring Assignment</h3><p>This fantastic feature of ES6 makes the assignment of values from arrays or objects a piece of cake. it’s done this way:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b961297f4b0b183389310c9387e89549/href">https://medium.com/media/b961297f4b0b183389310c9387e89549/href</a></iframe><p>Note: If you assign a variable that is not identical to the name of the property, it will return undefined. For example, if the name of the property is breed and we assign it to a dogType variable,<strong> </strong>it will return undefined. We always have to name the variable the same as the name of the property. But in case we want to rename the variable, we can use the colon (:) instead. like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0162d143710b2ff96463cb00ada9e1c7/href">https://medium.com/media/0162d143710b2ff96463cb00ada9e1c7/href</a></iframe><p>Similarly for arrays:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b96f8bcf43e9b7efdde1db338e91e1bb/href">https://medium.com/media/b96f8bcf43e9b7efdde1db338e91e1bb/href</a></iframe><h3>Enhanced Object Literals</h3><p>The improvement of object literals in ES6 is mind-blowing. let’s take a look at an example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a5950a70ae79877afe8d71a3e7b36ca/href">https://medium.com/media/2a5950a70ae79877afe8d71a3e7b36ca/href</a></iframe><p>so easy, isn’t it?</p><h3>Arrow Functions</h3><p>This is probably the most magical features of ES6 that beat my imagination. The syntax is accomplished by the use of the fat arrow (=&gt;). For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2bbd9a14671c6c938a7abdd42b9c35a/href">https://medium.com/media/c2bbd9a14671c6c938a7abdd42b9c35a/href</a></iframe><p>Another example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d6ae9025dc04196853badec59dbc3453/href">https://medium.com/media/d6ae9025dc04196853badec59dbc3453/href</a></iframe><p>That fat arrow is amazing because it would make this keyword behave properly, i.e., this will have the same value as in the context of the function—it won’t mutate. The mutation typically happens each time you create a closure. Using arrows functions in ES6 allows us to stop using that = this or self = this or _this = this or .bind(this). For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8fe4cb3bfcf498c51997690d6bf778d4/href">https://medium.com/media/8fe4cb3bfcf498c51997690d6bf778d4/href</a></iframe><p>To read more on arrow function click <a href="https://medium.freecodecamp.org/when-and-why-you-should-use-es6-arrow-functions-and-when-you-shouldnt-3d851d7f0b26">here</a></p><h3>Promises</h3><p>This new feature is used to perform an asynchronous task in Javascript. This comes handy especially when you want to get some data over an API, or when we have a function that takes time to be executed. Promises make it easier to solve the problem. Here is an example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0474972cfa10253e786cb25dc79e7d6a/href">https://medium.com/media/0474972cfa10253e786cb25dc79e7d6a/href</a></iframe><h3>Classes</h3><p>The class feature of ES6 is syntactic sugar of the core prototype oriented pattern of Javascript. This feature was added to make developers from other Object-oriented languages like Java etc feel at home in Javascript environment. It looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/376c6255e51991254b6ae938f189a9e5/href">https://medium.com/media/376c6255e51991254b6ae938f189a9e5/href</a></iframe><p>To create a class, use the class keyword followed by the name of the class with two curly brackets. And each class should have a means of creating objects from it, hence the constructor(){} .</p><p>To add attributes to the class we can do:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec9200372185726c3b4324b1f43f2509/href">https://medium.com/media/ec9200372185726c3b4324b1f43f2509/href</a></iframe><p>To read more on classes click <a href="https://medium.com/tech-tajawal/javascript-classes-under-the-hood-6b26d2667677">here</a></p><h3>Modules, Import and Export</h3><p>As you might know, there was no native modules support in JavaScript before ES6. People came up with RequireJS, CommonJS, and other workarounds. Now there are modules with import and exportoperands.</p><p>In ES5 you would use &lt;script&gt; tags with Immediately invoked functions expressions (IIFE), or some library like RequireJS, while in ES6 you can expose your class with export. Let’s say we have name variable and sayMyName method in ES5 module.js:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d292ad884b6f5112ee288787a201f4b4/href">https://medium.com/media/d292ad884b6f5112ee288787a201f4b4/href</a></iframe><p>But in ES6 we would achieve that by simply using export and import respectively:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f8fb1f37575df4ce4cdb486b5f0d43b7/href">https://medium.com/media/f8fb1f37575df4ce4cdb486b5f0d43b7/href</a></iframe><p>Notice how we put the identifier name we want to import in a curly bracket. If you are importing more than one variable or function, just add it inside the curly bracket separated by a comma. For more reading on this click <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import">here</a></p><h3>Generators</h3><p>Functions in JavaScript, as we all know, executes until it returns or ends<strong><em>. </em></strong><em>Similarly,</em><strong><em> Generator Functions </em></strong><em>runs until yield, return or ends. </em>Unlike the normal functions <strong>Generator Functions</strong> once called, returns the <strong>Generator Object, </strong>which holds the entire <strong>Generator Iterable</strong> that can be iterated using <strong>next()</strong> method or <strong>for…of </strong>loop. Generator functions are written using the function* syntax. let&#39;s see an example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/87756bd4753cde36bffd4fa6b603c732/href">https://medium.com/media/87756bd4753cde36bffd4fa6b603c732/href</a></iframe><h3>Rest and Spread operator</h3><p><a href="https://developer.mozilla.org/ar/docs/Web/JavaScript/Reference/Functions/rest_parameters">The rest parameter</a>s are used to get arguments as an array and return a new array. This operator enables developers to convert arguments into an array. Example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/387b8bf6da83a140357df10a475097e5/href">https://medium.com/media/387b8bf6da83a140357df10a475097e5/href</a></iframe><p>The spread operator has the same syntax as the rest parameter, but the spread operator takes the Array itself and not just the arguments. We can use the Spread parameter to get the values of an Array, instead of using a for loop or any other method. for example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c23879a6ec564458dda8b05ca29b2534/href">https://medium.com/media/c23879a6ec564458dda8b05ca29b2534/href</a></iframe><h3>Conclusion</h3><p>That&#39;s it guys, hope you found this article useful and hope I was able to bring you up to speed with the key ES6 features and how to use them.</p><p>Please feel free to drop your feedback about the article, Bye.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8513177c966" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Concept of Prototype Oriented programming (POP) in Javascript]]></title>
            <link>https://medium.com/@matthiasogbodo/concept-of-prototype-oriented-programming-pop-in-javascript-c7c8828cc807?source=rss-706bd7fb1eb1------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7c8828cc807</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[prototype]]></category>
            <category><![CDATA[oop-concepts]]></category>
            <category><![CDATA[prototyping]]></category>
            <category><![CDATA[pop]]></category>
            <dc:creator><![CDATA[Izuking Ogbodo]]></dc:creator>
            <pubDate>Sat, 11 May 2019 15:43:41 GMT</pubDate>
            <atom:updated>2019-05-11T16:08:29.476Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fpL2U6OReznBn1WkSZ4wAg.png" /></figure><p>Hi everyone, today we shall be seeing how object-oriented programming paradigm is being implemented in Javascript.</p><p>But before we look into that, let’s take a shallow dive into the concept of object-oriented programming paradigm itself as it relates to other languages like Java, Python, Ruby C++, PHP, Javascript, etc…</p><h4>Object-Oriented Programming (OOP)</h4><p>Object-Oriented Programming is a programming style that is related to the concepts of Class, Objects, and various other concepts like <strong>Inheritance</strong>, <strong>Abstraction</strong>, <strong>Encapsulation</strong>, and <strong>Polymorphism</strong>.</p><p>In other words, it is a programming language model in which programs are written in an organized way focusing more around data, or objects, rather than functions and logic.</p><h4>Concepts of OOP</h4><p>As earlier stated in the above explanation of OOP, the Object-oriented programming is based on the following concepts:</p><ul><li><strong>Inheritance: </strong>Relationships and subclasses between objects can be established, allowing developers to reuse a common logic while still maintaining a unique hierarchy. This property of OOP forces a more thorough data analysis, reduces development time and ensures a higher level of accuracy in the program being developed.</li><li><strong>Abstraction:</strong> Objects only reveal internal mechanisms that are relevant for the use of other objects, hiding any unnecessary implementation code. This concept helps developers make changes and additions over time more easily seamlessly.</li><li><strong>Encapsulation:</strong> The implementation and state of each object are privately held inside a defined boundary or class. Other objects do not have access to this class or the authority to make changes but are only able to call a list of public functions or methods. This characteristic of <strong>data hiding</strong> provides greater program security and avoids unintended <strong>data corruption</strong> in your program.</li><li><strong>Polymorphism:</strong> Objects are allowed to take on more than one form depending on the context. The program will determine which meaning or usage is necessary for each execution of that object, cutting down code redundancy in the program.</li></ul><p>This is how deep we can go in OOP. Now let’s continue with the subject matter which is object orientated programming in Javascript.</p><p>Unlike other object orientated programming languages we mentioned above which Javascript is among, Javascript, however, implemented this concept in an entirely different way from others.</p><p>Javascript employs the prototypal oriented programming pattern (POP) to implements the concept of OOP.</p><h4>Prototype Oriented Programming</h4><p>Prototype oriented programming (POP) is a style of object-oriented programming (OOP) in which classes are not explicitly defined, but instead derived by adding properties and methods to an instance of another class or, less frequently, adding them to an empty object.</p><p>In order word, this style of programming is based on cloning and reusing already created object to construct another object in a program or applications.</p><p>In simple term, this type of programming concept allows the creation of an object without first defining its class.</p><p>This programming context and its core frameworks are similar to an object-oriented programming structure, but it uses a classless inheritance programming style in creating <strong>duplicate</strong> object instances.</p><p>Prototype-based programming is also known as prototypal programming, prototype-oriented programming, classless programming or instance-based programming.</p><p>Prototype-based programming primarily works on the concept of object cloning and prototyping. It utilizes object inheritance, where one object can be reused by another object without the need for creating any parent class.</p><p>In JavaScript, when using a “prototype” function/method; an object can be called/used in another program without defining its class(the class keyword is introduced in ES2015, but is syntactical sugar, JavaScript remains prototype-based). The JavaScript creates a link between the new object and the primary object. The cloned/copied/prototyped object works the same way as the primary object.</p><p>JavaScript, Action Script, and Newton Script are some prototype-based programming languages.</p><p>To further buttress this concept of prototype object programming, we shall explore a project titled <strong>Lecture Manager</strong>.</p><p>The complete source code of the project can be found on<a href="https://github.com/ogbodo/LectureManager"> GitHub</a>.</p><p>I know you might probably be asking since Javascript implements object-oriented programming as prototypal programming, how can <strong>inheritance</strong>, <strong>encapsulation</strong>, <strong>polymorphism, </strong>and <strong>abstraction</strong> be achieved?</p><p>Funny enough, Javascript implements these concepts in an entirely different way from the normal convention of Java etc, but still achieves the essence of the concepts.</p><p>When it comes to <strong>inheritance</strong>, JavaScript only has one construct: objects. Each object has a private property which holds a link to another object called its prototype. That prototype object has a prototype of its own, and so on until an object is reached with null as its prototype. By definition, null has no prototype and acts as the final link in this <strong>prototype chain</strong>.</p><p>Nearly all objects in JavaScript are instances of Object which sits on the top of a prototype chain.</p><p>It is important to note that the prototypal inheritance model itself in Javascript is, in fact, more powerful than the classic model. It is, for example, fairly trivial to build a classic model on top of a prototypal model.</p><h4>Inheritance with the prototype chain</h4><p>JavaScript interprets each object on the fly, which makes it a dynamic programming language. objects are dynamic “bags” of properties (referred to as <strong>own properties</strong>). JavaScript objects have a link to a prototype object. When trying to access a property of an object, the scope to consider will have to go all the way up from the object in consideration to the prototype chain of that object until either a property with a matching name is found or the end of the prototype chain is reached as explained above.</p><p>let’s look at the use case of putting all we have learned until this stage into exploring the<strong> lecture manager</strong> project I mentioned from the beginning of this article.</p><h4>Problem Statement</h4><p>Assuming higher institution running a six-month program hired you to develop a software that enables only their lecturers to manage their lecture timetables.</p><p>looking at the problem statement we can see that it a big project in real life. But because of the fact that we just want to use it to cement our knowledge of Prototype Oriented programming in Javascript, we are not going to dive deep into the solution. Remember you can get the complete source code for this project on<a href="https://github.com/ogbodo/LectureManager"> GitHub</a>. I have tried my possible best to explain the code here.</p><p>First thing first, let’s create our super object named User.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1741aa32a425af6f92a84d6e9a7c25b8/href">https://medium.com/media/1741aa32a425af6f92a84d6e9a7c25b8/href</a></iframe><p>In the above code, from line 17 down to line 47, you will observe how functionalities you intend to be inherited by other object are placed inside the User object prototype.</p><p>You might be wondering what the point of this is. We can just attach this method inside the constructing function itself, like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/77d4d9ce801ee307144c7adc0233e0ce/href">https://medium.com/media/77d4d9ce801ee307144c7adc0233e0ce/href</a></iframe><p>This works too but has performance and memory issues. what happened here is that each child object created from the object will have its <strong><em>own version</em></strong> of all the instance <strong>methods</strong> placed directly on the child object. They’ll be distinct functions in memory.</p><h4>Performance</h4><p>The concern for performance becomes handy when you need thousands of new objects created from a constructor function. Using this second approach of attaching <strong>methods</strong> inside the constructor, we now have thousands of copies of those <strong>methods</strong>, each one attached to one of the objects.</p><p>But using the prototype chain method(ie the first approach), no matter how many objects we create out of the User object, we have one copy of each methods sitting on User.prototype.</p><p>Statistically, If an object needs access to 10 methods and we create 100 objects, the JavaScript engine has created 1,000 new functions.</p><p>But If this scenario needs to happen multiple times, this will cause noticeable speed and memory issues. However, considering having a total of 10 functions and giving each object the ability to use the same functions through the prototype chain; you will agree with me that it’s much more scalable.</p><p><strong><em>Please only modify your own prototypes. Never modify the prototypes of standard JavaScript objects.</em></strong></p><p>Now let’s have two child objects Lecturer and Admin inherit instance properties and methods of theUser object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/117d0716aa98a889a48dd56bc77a0317/href">https://medium.com/media/117d0716aa98a889a48dd56bc77a0317/href</a></iframe><p>Let me quickly explain Object.create() as used in this article.</p><p>The Object.create() was introduced in ECMAScript 5. Calling this method creates a new object. The prototype of the User object is the first argument of the function and returns a brand new object whose __proto__ property is equal to the object that was passed in.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c596cb0b1e8d71e8df86c6d297de3f74/href">https://medium.com/media/c596cb0b1e8d71e8df86c6d297de3f74/href</a></iframe><p>If you look at the highlighted portion of the commented code, you will notice how the Lecturer and Admin objects inherit both instance properties and methods (which are defined in the prototype) of the User object. This way, code reusability is achieved; which is the sense behind the concept of inheritance in object-oriented programming pattern but implemented using the prototypal approach in Javascript.</p><p>This is the core principle behind the Prototype Oriented Programming (POP) in Javascript.</p><h3>Summary</h3><p>In conclusion, inheritance in JavaScript is implemented via the prototype chain. Every normally created object, array, and function has a prototype chain of __proto__ properties ending with Object.prototype at the top. This is why they’re all considered first-class objects in JavaScript.</p><p>Functions have a prototype property in addition to the __proto__ property. When using a constructor function with new, it’s good practice to place methods on the function’s prototype instead of on the object itself as already explained above. The returned object __proto__ will be equal to the function’s prototype so it will inherit all methods on the function’s prototype. This prevents unnecessary memory usage and improves speed in program execution.</p><p><strong><em>That’s It. If this was helpful, please clap for it on the left side of this page so this article reaches more people. Also, feel free to check out my follow-up article where I explain testing Javascript code using the above topic.</em></strong></p><h3>For Further reading</h3><ul><li><a href="https://www.quora.com/What-are-encapsulation-inheritance-polymorphism-and-abstraction">https://www.quora.com/What-are-encapsulation-inheritance-polymorphism-and-abstraction</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object-oriented_JS">https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object-oriented_JS</a></li><li><a href="http://voidcanvas.com/es6-private-variables/">http://voidcanvas.com/es6-private-variables/</a></li><li><a href="https://medium.com/@rajaraodv/is-class-in-es6-the-new-bad-part-6c4e6fe1ee65">https://medium.com/@rajaraodv/is-class-in-es6-the-new-bad-part-6c4e6fe1ee65</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Inheritance">https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Inheritance</a><br>* <a href="https://en.wikipedia.org/wiki/Object-oriented_programming">https://en.wikipedia.org/wiki/Object-oriented_programming</a></li><li><a href="https://en.wikipedia.org/wiki/Object-oriented_programming">https://en.wikipedia.org/wiki/Object-oriented_programming</a></li><li><a href="https://medium.freecodecamp.org/a-guide-to-prototype-based-class-inheritance-in-javascript-84953db26df0">https://medium.freecodecamp.org/a-guide-to-prototype-based-class-inheritance-in-javascript-84953db26df0</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7c8828cc807" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing Javascript Code]]></title>
            <link>https://medium.com/@matthiasogbodo/testing-javascript-code-6ca916da964a?source=rss-706bd7fb1eb1------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ca916da964a</guid>
            <category><![CDATA[test-driven-development]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[tdd]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Izuking Ogbodo]]></dc:creator>
            <pubDate>Sat, 11 May 2019 15:29:22 GMT</pubDate>
            <atom:updated>2019-05-11T15:29:22.192Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*Wn6t4Ic3zfykRv253ZCUGg.png" /></figure><p>I know you might be asking why should I spend more time on writing tests if I can make my code work fine? The answer is simple, nobody is perfect; a simple bug that would have lingered for long would be easily discovered and fixed during testing. It makes you think and reason better, as well as keeps your code easier to maintain and improves its accuracy, plus It’s also fun.</p><p>Testing JavaScript code can be a pain. But a lot of tools, techniques, and frameworks have been developed to make your life easy when testing your codebase. Some of these tools are Mocha, Jasmine and Jest.</p><h4>What is Testing?</h4><p>Testing in this context is the process of evaluating a part or unit of your program to detect differences between given input and expected output. Testing assesses the quality of your application. Software testing is a process that should be done during the development process.</p><h4>Why Test?</h4><p>The sense behind testing is to make sure that the code in your application does what you expect it to do, and keeps doing what you expect it to do when you make changes so you have a working product when you’re totally done. You write a test that defines your expected functionality under a defined set of circumstances, run that test against the code, and if the result isn’t what the test says it should be, you get a warning which will give you clue on how to fix the bug in your codebase. And yes, it will make you feel good. Consider a simple division function.</p><pre>var divide = (a,b) =&gt; {return a / b}</pre><p>Seems like a nice little pure function to me. But what if it doesn’t exist in the folder you’re working on? Perhaps you forgot to import or export it. What if strings get passed to your function instead of numbers? What if only one parameter gets passed in? What if other functions relied on the output of this function? What if zero is passed as the second parameter? and whole lots of what if…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*sT665H7ZLMz8Bn-4bC26sg.jpeg" /></figure><p>But writing tests for our functions avoid these simple yet expensive mistakes that could happen, and as your application grows, the expense of faulty code (bugs) decreases.</p><p>You can write a test at any point in the coding process, but its best practice and I’ve always found that it&#39;s most efficient to write a unit test before writing the function you’re planning to test. This practice is known as test-driven development (TDD).</p><p>TDD encourages you to break down the functionality of your application before you start writing and determine what results you want from each section of code, writing the test first, then coding to produce that result.</p><p>Most importantly, TDD often forces you to have a detailed analysis of the problem you want to proffer solution to and make sure that you are writing modular and testable code. It’s easy to make a single test pass. What’s hard is determining what to do with all the likely inputs you’re going to encounter and handle them all correctly without breaking the already working parts.</p><h4>Types of testing</h4><ul><li><strong>Unit testing — </strong>Testing small chunks of our code in isolation from other codes to ensure the code is optimal</li><li><strong>Integration testing — </strong>Testing combinations of units and how they work together</li><li><strong>Acceptance testing — </strong>Testing an application in the browser or on a device to analyze the performance of the entire application.</li></ul><p>Today, I’ll be explaining how the principles of testing Javascript code works. This is actually a follow-up article on the <a href="https://medium.com/p/c7c8828cc807/edit">Concept of Prototype Oriented programming (POP) in Javascript</a> where <a href="https://github.com/ogbodo/LectureManager">Lecture manager</a> program was used for illustration. In this article, I’ll show you how to get up and running with the Jest framework and solidify your knowledge on that by performing tests on our <a href="https://github.com/ogbodo/LectureManager">Lecture manager</a> program; so you will have the feel on using a test-driven development (TDD) approach on your program before rolling it out to production with Node.js. In case you’re unfamiliar, Node.js allows the use of JavaScript on the server side. <a href="https://www.taniarascia.com/how-to-install-and-use-node-js-and-npm-mac-and-windows/">Read the getting started article</a> to get up to speed with Node.js. We shall be using the <a href="https://jestjs.io/docs/en/getting-started">Jest</a> framework in testing our program because it’s pretty easy to set up than others plus it’s well-documented and can be extended to match your requirements.</p><h4>Prerequisites</h4><ul><li>In order to follow along with this tutorial, you should have a Node.js server environment and npm installed on your computer. <a href="https://www.taniarascia.com/how-to-install-and-use-node-js-and-npm-mac-and-windows/">Learn about Node.js and npm</a> and how to install them on Mac/Windows.</li><li>You will need to have a working knowledge of JavaScript <a href="https://www.digitalocean.com/community/tutorials/understanding-syntax-and-code-structure-in-javascript">syntax and code structure</a>, <a href="https://www.digitalocean.com/community/tutorials/understanding-data-types-in-javascript">data types</a>, <a href="https://www.digitalocean.com/community/tutorials/how-to-write-conditional-statements-in-javascript">conditional statements</a> and <a href="https://medium.com/p/c7c8828cc807/edit">Concept of Prototype Oriented programming (POP) in Javascript</a>.</li></ul><h4>Setup the Environment for Jest</h4><p>Since our program runs in Node.js, we will have to set up a local environment for our files and dependencies.</p><p>Clone the <a href="https://github.com/ogbodo/LectureManager">Lecture manager</a> project into your working directory.</p><p>Locate and open the following test files Lecturer.test.js and Admin.test.js. These files contain all the possible scenarios that have been accounted for in our <a href="https://github.com/ogbodo/LectureManager">Lecture manager</a> application. The content of these files are:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/168987ea9f3bbce03b80ce59287e476f/href">https://medium.com/media/168987ea9f3bbce03b80ce59287e476f/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3cf10ee4e4020bb3285f837ec335f6b/href">https://medium.com/media/b3cf10ee4e4020bb3285f837ec335f6b/href</a></iframe><p>If you take a closer look, all we used here is the methodtest(name, fn, timeout<em>(optional)</em>) which takes mainly two arguments.</p><p>The first argument is the test name; the second argument is a function that contains the expectations to test. The third argument (optional) is timeout (in milliseconds) for specifying how long to wait before aborting. <em>Note: The default timeout is 5 seconds.</em></p><p>In the command prompt, navigate to the directory and install the jest framework for testing: npm init npm install --save-dev jest.</p><p>To run all test cases: npm test</p><p>when you run the test you should see the test pass similar to the image below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uxn5g2dGv_clL_Qw1yX0Aw.png" /></figure><p>Everything went through successfully and our output was as expected.</p><p>I encourage you to download the full project from <a href="https://github.com/ogbodo/LectureManager">GitHub</a> and try out all we have discussed in <a href="https://medium.com/p/c7c8828cc807/edit">Concept of Prototype Oriented programming (POP) in Javascript</a> and this follow-up article to get the same result as above.</p><h4>Conclusion</h4><p>We just covered the basics of test-driven development (TDD) through the creation of <a href="https://github.com/ogbodo/LectureManager">Lecture manager</a> program in Node.js and used the Jest framework for testing.</p><p><strong><em>If this was helpful, please clap for it on the left side of this page so this article reaches more people and please be in touch for more...</em></strong></p><h3>For Further reading</h3><ul><li><a href="https://flaviocopes.com/jest/">https://flaviocopes.com/jest/</a></li><li><a href="https://jestjs.io/">https://jestjs.io/</a></li><li><a href="http://zetcode.com/javascript/jest/">http://zetcode.com/javascript/jest/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ca916da964a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>