<?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 Egi Mata on Medium]]></title>
        <description><![CDATA[Stories by Egi Mata on Medium]]></description>
        <link>https://medium.com/@egimata?source=rss-bdda66ff4bf5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Y00SEUI20u7VtdbBWIc7Zg.png</url>
            <title>Stories by Egi Mata on Medium</title>
            <link>https://medium.com/@egimata?source=rss-bdda66ff4bf5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 02:43:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@egimata/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[Understanding and Creating the Bounding Box of a Geometry]]></title>
            <link>https://medium.com/@egimata/understanding-and-creating-the-bounding-box-of-a-geometry-d6358a9f7121?source=rss-bdda66ff4bf5------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6358a9f7121</guid>
            <category><![CDATA[3d]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[threejs]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Egi Mata]]></dc:creator>
            <pubDate>Tue, 08 Aug 2023 11:15:20 GMT</pubDate>
            <atom:updated>2023-08-08T11:17:28.020Z</atom:updated>
            <content:encoded><![CDATA[<p>In computer graphics, computational geometry, and 3D modeling, working with geometries is essential. A fundamental operation when dealing with geometries is determining the bounding box, which defines the minimum <em>axis-aligned</em> rectangle or a cuboid that surrounds the entire geometry.</p><figure><img alt="Understanding and creating the bounding box of a geometry" src="https://cdn-images-1.medium.com/max/1024/1*ceIqAZMUGtwkzPMPU6gKRg.png" /></figure><h3>Understanding the Bounding Box</h3><p>A <strong>bounding box </strong>is a <a href="https://en.wikipedia.org/wiki/Cuboid">cuboid</a>, or in 2D a <a href="https://en.wikipedia.org/wiki/Rectangle">rectangle</a>, containing the geometry object, which defines the spatial extent of the latter.</p><p>The box acts as an invisible container that wraps around the entire geometry, providing a quick and efficient way to determine its size, position, and collision detection ( see image below ).</p><figure><img alt="Bounding Box of a Bunny ( From Three.js examples )" src="https://cdn-images-1.medium.com/max/788/1*w0tpVI_VRLcQZ6zTOn7D0w.png" /><figcaption>Bounding Box of a Bunny ( From Three.js examples )</figcaption></figure><p>*<em>In many applications, the bounding box is aligned with the axes of the coordinate system, and it is then known as an </em><strong><em>axis-aligned bounding box</em></strong><em> (</em><strong><em>AABB</em></strong><em>). To distinguish the general case from an AABB, an arbitrary bounding box is sometimes called an </em><strong><em>oriented bounding box</em></strong><em> (</em><strong><em>OBB</em></strong><em>), or an </em><strong><em>OOBB</em></strong><em> when an existing object’s </em><a href="https://en.wikipedia.org/wiki/Local_coordinate_system"><em>local coordinate system</em></a><em> is used. AABBs are much simpler to test for intersection than OBBs but have the disadvantage that when the model is rotated they cannot be simply rotated with it, but need to be recomputed ( we will cover this in another article ). “from </em><a href="https://en.wikipedia.org/wiki/Bounding_volume"><em>Bounding Volume</em></a><em>”</em></p><p>In this article, I will explain how to use the bounding box in 3D graphics, and demonstrate how to dynamically create a bounding box from geometry data using TypeScript.</p><h3>3D Geometries</h3><p>In 3D graphics, geometry is a collection of <strong>vertices</strong>, <strong>edges</strong>, and <strong>faces </strong>that represent a 3-dimensional object. These geometries can be as simple as a cube or as complex as a detailed 3D model of a character or environment. Regardless of complexity, each geometry can be described as a set of points in 3D space, and from this data, we can calculate its bounding box.</p><h3>Calculating the Bounding Box</h3><p>A bounding box is defined by two opposite corners ( acting as a <strong><em>vector 3</em></strong> (x, y, z) ) in 3D space:</p><ul><li>the minimum point → <em>minimum_x</em>, <em>minimum_y</em>, <em>minimum_z</em></li><li>the maximum point → <em>maximum_x</em>, <em>maximum_y</em>, <em>maximum_z</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GXU5qXjVU5EaS5hkle6H2A.png" /></figure><blockquote>Values of min &amp; max in this rectangle are fictive, just to show how they could be in reality. It’s important only that we know where these points are located in a box in the 3D view.</blockquote><p>To calculate the bounding box of a given geometry, we need to process its vertices and find the minimum and maximum coordinates along each axis (x, y, z). We need to:</p><ol><li>Parse Geometry Data: If you’re working with 3D models from file formats like OBJ or FBX, you’ll need to parse the data to extract the vertices.</li><li>Find Minimum and Maximum Coordinates: Iterate through the vertices and find the minimum and maximum coordinates along the x, y, and z axes.</li><li>Construct the Bounding Box: With the <strong>minimum </strong>and <strong>maximum </strong>coordinates, construct the bounding box by defining the two corners.</li></ol><h4>Here’s a step-by-step approach using TypeScript:</h4><p>First, we define interfaces for the Vector3 and BoundingBox to assign the values.</p><p>Vector 3 represents a point in 3D space. Each point has three properties: x, y, and z, corresponding to the coordinates along the x, y, and z axes, respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9QE3ctOOTm5frtLpRN6Nvg.png" /></figure><p>Next, let’s say we have already loaded a geometry model and extracted its <strong>vertices </strong>as an array of numbers, we would need to create a method to iterate through all vertices and find the <em>minimum </em>and <em>maximum </em>values, as Vector3, which computes the bounding box.</p><p>We loop through all the <strong>vertices </strong>in the vertices array. For each <strong>vertex</strong>, we compare its <strong>x</strong>, <strong>y</strong>, and <strong>z</strong> coordinates with the current <em>minimum </em>and <em>maximum </em>values. If any of the <strong>vertex </strong>coordinates are smaller than the current <em>minimum </em>value, we update the corresponding <em>minimum </em>value. Likewise, if any of the <strong>vertex </strong>coordinates are larger than the current <em>maximum </em>value, we update the corresponding <em>maximum </em>value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MP11toQO0c932Ke5dGW-Qg.png" /></figure><p>Breaking downcalculateBoundingBox method:</p><p><strong>1</strong>. The function takes an array of Vector3[] vertices as input. It returns an object with two properties, min and max, representing the minimum and maximum points of the bounding box, respectively.</p><p><strong>2</strong>. Inside the function, two variables, min and max, are initialized to represent the initial minimum and maximum points of the bounding box. We set them to extreme values (Infinity and -Infinity, respectively) so that any point in the geometry will always be considered smaller than the initial minimum and larger than the initial maximum when we perform the comparisons.</p><p><strong>3</strong>. After iterating through all the vertices, min will contain the smallest x, y, and z values found in the geometry, and max will contain the largest x, y, and z values found.</p><p>Finally, we return an object containing the calculated min and max points, which together define the bounding box of the geometry. The calling code can then use these values to determine the bounding box&#39;s dimensions and position.</p><h3>Generate Box Vertices</h3><p>Having only the <em>minimum </em>and <em>maximum </em>values of the bounding box doesn’t give us all eight vertices of the cuboid directly. However, we can easily generate the eight vertices of the bounding box using just these two edge points.</p><p>A cuboid (box) in 3D space has eight vertices, which can be defined using the <em>minimum </em>and <em>maximum </em>points of the bounding box. The eight vertices can be calculated by combining the <strong>x</strong>, <strong>y</strong>, and <strong>z</strong> coordinates of the <em>edge</em> points in all possible combinations.</p><p>The easiest and basic way to do this is to create each vertex as a Vector3:</p><pre>const verticesAsVector3: Vector3[] = [<br>   { x: min.x, y: min.y, z: min.z }, // 0<br>   { x: min.x, y: min.y, z: max.z }, // 1<br>   { x: min.x, y: max.y, z: min.z }, // 2<br>   { x: min.x, y: max.y, z: max.z }, // 3<br>   { x: max.x, y: min.y, z: min.z }, // 4<br>   { x: max.x, y: min.y, z: max.z }, // 5<br>   { x: max.x, y: max.y, z: min.z }, // 6<br>   { x: max.x, y: max.y, z: max.z }, // 7<br>];</pre><p>Comments in the code indicate the index and the combination for each vertex. Then we iterrate through values of all Vector3 vertices and push them to an array of numbers.</p><pre>const vertices: number[] = [];<br>  // To array<br>for ( const vertex of verticesAsVector3 ) {<br>     vertices.push( vertex.x );<br>     vertices.push( vertex.y );<br>     vertices.push( vertex.z );<br>}</pre><p>The final method would return the vertices array.</p><blockquote>The way I am creating the geometry using Three.js I need vertices in an array of numbers, but if your graphics library needs vertices as array of vertices, you don’t have to proceed with this loop to get the array of numbers.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R8DfjuzjMORGv_IM__8m0g.png" /><figcaption>Method to generate the vertices of the geometry bounding box</figcaption></figure><p>Finally, after combining all the methods, we will get the bounding box generated in the 3D scene.</p><p>But this is not over yet. We may have all the vertices set in the view but at this point, we would see nothing yet. That is because we did not connect any of these vertices.</p><p>In addition to generating the vertices, we also need to define the <em>indices </em>( connectivity between two vertices ) that form the faces of the bounding box. A bounding box is typically represented as a <strong>wireframe </strong>cube, and we need the <em>indices </em>to specify the order in which the vertices should be connected to form the edges of the cube.</p><p>Lets declare the indices of a cuboid:</p><pre>function generateBoundingBoxIndices(): number[] {<br>   // Define the indices for the edges of the bounding box<br>   const indices: number[] = [<br>    0, 1, 1, 3, 3, 2, 2, 0, // Bottom face<br>    4, 5, 5, 7, 7, 6, 6, 4, // Top face<br>    0, 4, 1, 5, 2, 6, 3, 7  // Connecting edges<br>   ];<br>   return indices;<br>}</pre><p>Now we will be able to see the geometry surrounded by its bounding box.</p><p>For this example, I am using Three.js just for the rendering part, and I have created a simple triangular pyramid geometry. The final view will be this:</p><figure><img alt="Image of the goemetry with the bounding box." src="https://cdn-images-1.medium.com/max/1024/1*2Gpd6q6WPgRiX7_2R3Kguw.png" /><figcaption>Image of the goemetry with the bounding box.</figcaption></figure><p>As you see here the pyramid is surrounded by a white box perfectly, showing its bounding box.</p><p>With Three.js, you can efficiently calculate and visualize the bounding box of any geometry without manually iterating through each vertex to find the minimum and maximum values.</p><p>However, to provide a deeper understanding, I explained the fundamentals of how the bounding box works. This approach ensures that you have a clearer view when working with bounding boxes, rather than just relying on built-in library methods without understanding the principles.</p><h3>Conclusion</h3><p>Understanding and working with bounding boxes is fundamental in the field of computer graphics. Whether you decide to calculate it manually or utilize libraries like Three.js, the bounding box remains an indispensable tool for positioning, collision detection, and optimizing rendering performance in 3D applications.</p><p><em>Stay tuned</em> for more updates, and you can reach out if you have any specific topics or questions you’d like me to cover. I’m always happy to help and share my experience with WebGL, Three.js, and more!</p><h4>If you liked this article don’t hesitate to follow and leave a clap!</h4><p><em>See you on the next one..</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6358a9f7121" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simplifying Your Codebase: Best Practices for Organizing Types]]></title>
            <link>https://medium.com/@egimata/simplifying-your-codebase-best-practices-for-organizing-types-49bc78852559?source=rss-bdda66ff4bf5------2</link>
            <guid isPermaLink="false">https://medium.com/p/49bc78852559</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[beginner-coding]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Egi Mata]]></dc:creator>
            <pubDate>Sun, 28 May 2023 15:14:06 GMT</pubDate>
            <atom:updated>2023-05-28T15:14:26.848Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x9RWYeHxznxowlMcv5LSzw.png" /></figure><p>As developers, we all strive for a well-organized codebase that is easy to navigate and maintain. One crucial aspect of organizing code is effectively managing types. In this article, we will explore some best practices for organizing types in your application code, helping you simplify and streamline your development process.</p><h3>Group Types with Related Code</h3><p>When it comes to organizing types, it’s beneficial to keep them closely associated with the code they describe. By colocating types with the related implementation code, you can easily understand and modify both aspects of the code in one place. This approach enhances code readability and reduces the cognitive load of jumping between different files.</p><p>For example, if you have a JavaScript component called MyComponent that requires specific props, it&#39;s recommended to define the types directly within the same file:</p><pre>// MyComponent.ts<br>interface Props {<br>  foo: string,<br>  bar: number<br>}<br>/**<br> * MyComponent is a reusable component.<br> * @param {Props} props - The component props.<br> */<br>export const MyComponent = (props: Props) =&gt; {<br>  // Component implementation<br>};</pre><p>By colocating the type definition within the component file, you can easily refer to the type while working on the implementation. This approach ensures that the code remains self-contained and intuitive to work with.</p><h3>Extract Shared Types to a Separate Module</h3><p>While colocating types with their associated code is beneficial for single-use types, it may become impractical when multiple components or modules share the same types. In such cases, it’s advisable to extract the shared types into a separate module.</p><p>Create a dedicated module or file that houses the shared types, and import them wherever they are needed. This approach ensures consistency across your codebase and reduces duplication of type definitions.</p><p>For instance, consider a scenario where multiple components within your application require the same set of props. Instead of duplicating the type definitions in each component file, extract the shared types into a separate module:</p><pre>// components.types.ts<br>/**<br> * @typedef {object} Props<br> * @property {string} foo - The foo property.<br> * @property {number} bar - The bar property.<br> */<br>interface Props {<br>  foo: string,<br>  bar: number<br>}<br><br>export { Props };<br><br>// ----------------------------------------------- //<br><br>// Or you could export directly the interface by typing:<br>export interface Props {<br>  foo: string,<br>  bar: number<br>}</pre><p>Now, you can easily import the shared types in any component file that requires them:</p><pre>// MyComponent.js<br>import { Props } from &#39;./components.types.ts&#39;;<br>/**<br> * @param {Props} props - The component props.<br> */<br>const MyComponent = (props: Props) =&gt; {<br>  // Component implementation<br>};</pre><p>By centralizing shared types in a separate module, you promote code reuse, simplify maintenance, and ensure consistent type definitions throughout your application.</p><h3>Leverage Folder Structure for Type Organization</h3><p>In addition to colocating types and extracting shared ones, you can further enhance your codebase organization by leveraging your folder structure. By organizing your types based on their usage and scope, you can intuitively locate and manage them.</p><p>For instance, you can create a dedicated folder within your project structure to hold type-related files:</p><pre>|- src<br>  |- components<br>    |- MyComponent.ts<br>  |- types<br>    |- components.types.ts</pre><p>By following this approach, you can keep the types directly associated with the components they describe. This way, when working on a specific component, you know exactly where to find its corresponding types.</p><p>Additionally, if your application consists of multiple packages or modules, consider creating a separate package or module solely for shared types. This allows you to centralize and manage shared types efficiently, ensuring consistency across different parts of your codebase.</p><h3>Conclusion</h3><p>Organizing types effectively is crucial for maintaining a clean and understandable codebase. By colocating types with related code, extracting shared types to separate modules, and leveraging your folder structure, you can simplify your development process and improve code maintainability.</p><p>Remember, the goal is to strike a balance between keeping types close to their implementation and avoiding unnecessary duplication. Apply these best practices to your codebase and tailor them to suit your specific project requirements. Happy coding!</p><p>References: <a href="https://www.totaltypescript.com/">TotalTypeScript</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49bc78852559" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Desktop Apps with Electron JS: Part 1 — Getting Started with Electron]]></title>
            <link>https://javascript.plainenglish.io/building-desktop-apps-with-electron-js-part-1-getting-started-with-electron-dd3c914d24a9?source=rss-bdda66ff4bf5------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd3c914d24a9</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[desktop-app]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[electronjs]]></category>
            <dc:creator><![CDATA[Egi Mata]]></dc:creator>
            <pubDate>Fri, 03 Mar 2023 19:16:26 GMT</pubDate>
            <atom:updated>2023-03-06T04:58:10.453Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building Desktop Apps with Electron JS</h3><h4>Part 1 — Getting Started with Electron</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e__-bI5fVchECS4d8HWXvg.png" /><figcaption>Electron JS Series — Building Desktop Application — Part 1</figcaption></figure><p>I want to tell you my story on how I built my first desktop application.</p><p>I had zero knowledge on how I would get started but surely had heard of Electron.js before because of its name: “Electron”, it has a nice catch, during my studies which involved chemistry engineering (long story).</p><p>I came across it while I was working on my software development learning (not even JS, I was learning python and C++ back then) and somehow memorized its name and functionality that you can build a desktop application using JavaScript.</p><p>Before I begin to explain in detail I have to mention that this is going to be a complete <strong>series</strong> starting from <strong>beginner </strong>to <strong>advanced </strong>such as using also one of the latest frameworks as the main frontend/renderer part, that being either <strong>React </strong>or <strong>Angular</strong>. Although you need to have some basic knowledge on JavaScript.</p><p>With Electron, you can develop applications that work on <strong>Windows</strong>, <strong>macOS</strong>, and <strong>Linux </strong>using a single <strong>JavaScript </strong>codebase. It eliminates the need for native development experience, making it a <strong>cross-platform</strong> solution.</p><p>Some of the most well-known desktop applications that are built on Electron include:</p><ul><li><strong>Visual Studio Code:</strong> Microsoft’s popular code editor</li><li><strong>Slack: </strong>The popular team communication platform</li><li><strong>Discord:</strong> Another popular chat and voice communication app</li><li><strong>Atom:</strong> Another code editor</li><li><strong>GitHub Desktop: </strong>The official desktop client for the popular code hosting platform GitHub</li><li><strong>Microsoft Teams</strong></li></ul><h4>Let’s start with an overview of what we’ll cover in each part of the series.</h4><blockquote>Part 1: Introduction to Electron JS</blockquote><ul><li>What is Electron JS?</li><li>Setting up our development environment</li><li>Creating a window with a simple “<strong>Hello World</strong>” message</li><li>Adding some basic functionalities</li></ul><blockquote>Part 2: Using Angular as the main frontend/renderer</blockquote><ul><li>Understanding the main process and renderer process</li><li>What is Angular?</li><li>Why use Electron JS and Angular together?</li><li>Setting up the configurations to link Electron and Angular together</li></ul><blockquote>Part 3: Creating the User Interface</blockquote><ul><li>Creating the main process</li><li>Creating the renderer process</li><li>Creating the user interface using Angular</li></ul><blockquote>Part 3: Adding Functionality to the Application</blockquote><ul><li>Creating a service for the main process</li><li>Communicating between the main and renderer processes</li><li>Adding functionality to the user interface using Angular</li></ul><blockquote>Part 4: Packaging and Distributing the Application</blockquote><ul><li>Packaging our application for distribution</li><li>Creating an installer for the application</li><li>Distributing the application to users</li></ul><p>In the final part of this series, we’ll be packaging and distributing our application. We’ll go through the steps to package our application for distribution, create an installer for the application, and distribute the application.</p><h3>Getting Started with Electron JS</h3><p>Before we dive into building our first Electron application, we need to make sure we have the necessary tools installed. Here’s what you’ll need:</p><ul><li><strong>Node.js</strong></li><li><strong>NPM (Node Package Manager)</strong></li></ul><blockquote>You can find it in NodeJs official website <a href="https://nodejs.org/en/">https://nodejs.org/</a></blockquote><p><strong>NPM is included with Node.</strong> <strong>js installation</strong>. After you install Node.js, you can verify NPM installation by writing the following command in terminal or command prompt:</p><pre>npm -v</pre><p>an you will receive something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*aQ_4AoXFCLrR4CegjvBF4w.png" /></figure><p>which tells you the version of <strong>npm.</strong></p><p>Now that we have Node.Js installed, we can create our first Electron application. Here’s how:</p><p><strong>1.</strong> Create a new directory for your project, navigate to it and in your terminal initialize a new Node.js project with the following command:</p><pre>npm init</pre><p><strong>2.</strong> Next we want to install Electron.Js:</p><pre>npm install electron --save-dev</pre><p>Your package.json file should look something like this:</p><pre>{<br>  &quot;name&quot;: &quot;my-desktop-application&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;Hello World!&quot;,<br>  &quot;main&quot;: &quot;main.js&quot;,<br>  &quot;author&quot;: &quot;Whoever is reading this&quot;,<br>  &quot;license&quot;: &quot;MIT&quot;,<br>  &quot;devDependencies&quot;: {<br>    &quot;electron&quot;: &quot;22.0.0&quot;<br>  }<br>}</pre><p>after initializing your package and installing Electron. You should also now have a node_modules folder containing the Electron executable, as well as a package-lock.json lockfile that specifies the exact dependency versions to install.</p><p><strong>3.</strong> Create a new file named main.js in the root of your project directory. This file will contain the main process code for your Electron application.</p><pre>const { app, BrowserWindow } = require(&#39;electron&#39;);<br><br>function createWindow() {<br>  const win = new BrowserWindow({<br>    width: 800,<br>    height: 600,<br>    webPreferences: {<br>      nodeIntegration: true<br>    }<br>  });<br><br>  win.loadFile(&#39;index.html&#39;);<br>}</pre><p>The createWindow() function loads your web page into a new BrowserWindow instance.</p><p><strong>4. </strong>Create a new file named index.html in the root of your project directory. This file will contain the HTML, CSS, and JavaScript code for your Electron application.</p><p><strong>5. </strong>Add the following code to index.html to display a basic web page:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>  &lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;title&gt;My First Desktop App&lt;/title&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;<br>    &lt;h1&gt;Hello, Electron!&lt;/h1&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>6. </strong>Now inside the main.js insert after createWindow();, this function which tell the app when it’s ready to initiate. Basically this will create a <strong>promise</strong>, in which, if it is successful, we call inside the callback the createWindow(); function.</p><pre>// --- Rest of code above --- //<br><br>app.whenReady().then(() =&gt; {<br>  createWindow()<br>})</pre><p>We want to also create the functionality when to quit the application and close it. On Windows and Linux, closing all windows will generally quit an application entirely. To implement this pattern in your Electron app, listen for the app module’s <a href="https://www.electronjs.org/docs/latest/api/app#event-window-all-closed">window-all-closed</a> event, and call <a href="https://www.electronjs.org/docs/latest/api/app#appquit">app.quit()</a> to exit your app if the user is not on macOS.</p><p>Insert this code after app.whenReady():</p><pre>app.whenReady().then(() =&gt; {<br>  createWindow()<br>})<br><br>app.on(&#39;window-all-closed&#39;, () =&gt; {<br>  if (process.platform !== &#39;darwin&#39;) app.quit()<br>})</pre><p>The app object represents the Electron application. When all windows are closed, the window-all-closed event is triggered, and the callback function is called.</p><p>In this case, the callback function uses a conditional statement to check if the platform is not macOS.</p><blockquote>The process.platform property returns the platform the application is running on, and darwin is the identifier for macOS.</blockquote><p>If the platform is not macOS, app.quit() is called, which quits the application. This is because on macOS, it is common for applications to stay open even when all windows are closed, but on other platforms, it is usually expected that the application will quit when all windows are closed.</p><p>Now the final step:</p><p><strong>7. Run Electron</strong></p><blockquote>The main process in Electron is a Node.js runtime, which means that you can run any Node.js code using the electron command.</blockquote><p>To do so, you need to add electron . to the start command in the scripts field of your package.json file. This command instructs the Electron executable to locate the main script in the current directory and execute it in dev mode.</p><pre>{<br>  &quot;name&quot;: &quot;my-desktop-application&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;Hello World!&quot;,<br>  &quot;main&quot;: &quot;main.js&quot;,<br>  &quot;author&quot;: &quot;Whoever is reading this&quot;,<br>  &quot;license&quot;: &quot;MIT&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;start&quot;: &quot;electron .&quot;<br>  },<br>  &quot;devDependencies&quot;: {<br>    &quot;electron&quot;: &quot;22.0.0&quot;<br>  }<br>}</pre><p>and finally:</p><pre>npm run start</pre><p>This will initiate electron and in the end we will have a browser window like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cKv0_UKSQmkwEriYXi6XyQ.png" /></figure><p>I’ve chosen to use VS Code as my code editor for this project. On the left-hand side, you can see the project files, and on the right, you can see the Electron-generated browser window displaying the “hello” message we added to its HTML file. Additionally, there’s a menu toolbar included in the build, but we’ll cover how to edit it in our preferences later on.</p><p>Congratulations!! You have executed your first line of code in Electron!</p><p>In the next section, we will learn how to create user interfaces using HTML and load them into a native window with any changes made. Initially, we’ll only use JavaScript for the main renderer (frontend), and later on, we’ll switch to Angular.</p><p>Thank you and keep reading to learn more! See you at the next one.</p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>.</em></p><p><em>Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></p><p><strong><em>Interested in scaling your software startup</em></strong><em>? Check out </em><a href="https://circuit.ooo/?utm=publication-post-cta"><strong><em>Circuit</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd3c914d24a9" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/building-desktop-apps-with-electron-js-part-1-getting-started-with-electron-dd3c914d24a9">Building Desktop Apps with Electron JS: Part 1 — Getting Started with Electron</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[3D Web Development: How to use WebGL for Interactive 3D Graphics]]></title>
            <link>https://medium.com/@egimata/3d-web-development-how-to-use-webgl-for-interactive-3d-graphics-c0a38c6c8a3d?source=rss-bdda66ff4bf5------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0a38c6c8a3d</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[threejs]]></category>
            <dc:creator><![CDATA[Egi Mata]]></dc:creator>
            <pubDate>Thu, 09 Feb 2023 11:26:36 GMT</pubDate>
            <atom:updated>2023-03-05T11:57:23.406Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l1fZMlYos9rXJFwjnvoKSw.png" /><figcaption>3D Web Development — Adding 3D modeling inside web applications and interact with the 3D Environment</figcaption></figure><h4>Have you ever wondered if you could interact with 3D models inside your computer screen?</h4><p>Well of course you have, If you’ve ever played a modern video game on a console or computer, then you’re already familiar with the concept.</p><p>I am not talking about the old school games like Super Mario or Donkey Kong which were made in a 2D canvas. I mean the 3D video games where you have access to different models inside the 3D canvas in which you can interact with the terrain.</p><p>They are made using game engines that utilize mathematics and physics to create an immersive 3D environment that the player can interact with. Typically, low-level programming languages like C++ are used to create them. In the gaming industry, most of the big companies use their game engines that are built on the foundation of C++.</p><h4>Now here’s the thing…</h4><p>Imagine being able to bring this level of interactivity to the web development world. For example, you are visiting an e-commerce website that sells shoes. Instead of just looking at pictures of the shoes, you could interact with a full 3D model of the shoe in more detail.</p><p>It is more than possible to achieve this using something called <strong>WebGL</strong>.</p><blockquote>*At the end of the article you will have a real time 3D rendering of <strong>WebGL </strong>so you can try how it feels.</blockquote><h3>What is WebGL?</h3><blockquote>WebGL is a JavaScript API for rendering interactive 3D graphics in modern web browsers without the need for plugins.</blockquote><p>As a developer who is always pushing the boundaries of what’s possible with technology, lately using a lot of 3D visual design in web/desktop applications, I am thrilled to dive into the world of WebGL.</p><p>One tool that has greatly influenced and enhanced my work in this field is <strong>Three.js</strong>.</p><p>Three.js is a <strong>JavaScript </strong>library that allows you to create and display 3D graphics in the browser using WebGL.</p><ul><li>It is fast (<strong>very fast</strong> I might say),</li><li>Lightweight</li><li>Easy to use, making it possible for web developers to create complex 3D graphics in their projects.</li></ul><p>Three.js is also well-suited to game development thanks to its support for <strong>WebGL</strong>, which allows you to create fast and smooth 3D graphics that can run in the browser. Of course you won’t build a remastered version of <strong>Grand Theft Auto</strong>, but it helps you understand how the mechanics work.</p><h3>Creating 3D Graphics with WebGL and Three.js</h3><p>One of the things I love about Three.js is how easy it is to get started with.</p><p>Lets take as an example the shoes ecommerce website I mentioned above and create a 3D model of a shoe to show how it will look on the website.<br>Here’s how you would start:</p><h4><strong>1.</strong> <strong>Find a 3D shoe model</strong></h4><p>You can either create your own 3D model using 3D modeling software or find a pre-made model online. <br>For this example I will be using an existing one from Three.js.</p><h4><strong>2. Create a Canvas &amp; Renderer</strong></h4><p>We need a canvas to create the 3D environment and a renderer to animate/show the 3D space.</p><pre>//... HTML Part<br>&lt;canvas class=&quot;webgl&quot;&gt;&lt;/canvas&gt;<br><br>//... JavaScript<br>const canvas = document.querySelector(&#39;canvas.webgl&#39;);<br><br>/**<br> * Renderer<br> */<br>const renderer = new THREE.WebGLRenderer({<br>    canvas: canvas,<br>    antialias: true<br>})<br>// Size of the renderer window<br>renderer.setSize(window.innerWidth, window.innerHeight);<br>// Pixel ratio is set to render the scene properly in all devices<br>renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));</pre><h4><strong>3. Create a scene</strong></h4><p>In Three.js, you start by creating a scene, which is like a container. You place your objects, models in it, and you ask Three.js to render that scene.</p><pre>const scene = new THREE.Scene();</pre><h4><strong>4. Add a </strong><strong>Camera </strong>to the scene</h4><p>There are two(2) types of cameras: <strong>Perspective Camera </strong>and an <strong>Orthographic Camera</strong>.</p><ul><li><strong>Perspective Camera: </strong>Is designed to mimic the way the human eye sees.</li></ul><p>Perspective camera is the most common projection mode used for rendering a 3D scene so will use this one.</p><pre>/**<br> * Camera<br> */<br>const camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.25, 20 );<br>scene.add(camera)</pre><p>After creating successfully the scene and the camera we need to render it in the window. Usually this step is done in the end, but I want to show you the loaded model in the <strong>images </strong>below.</p><pre>const animate = () =&gt;<br>{<br>    // Render<br>    renderer.render(scene, camera)<br><br>    // Call tick again on the next frame<br>    window.requestAnimationFrame(animate)<br>}<br><br>animate();</pre><h4><strong>5. Load 3D model</strong></h4><p>We will use GLTFLoader to open a .gltf file, and add its path. Most 3D models come in .gltf format, but there are others like .stl, .glb, .obj, etc.</p><pre>const loader = new THREE.GLTFLoader();<br><br>loader.load(<br>  &#39;shoePath&#39;, (gltfFile) =&gt; {<br>  scene.add(gltfFile.scene);<br>});</pre><p>At this point we will have something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mbhFebVLhlQxC7OBVj4Ngw.png" /><figcaption>Loaded 3D Shoe Model</figcaption></figure><p>You may notice, of course, just a white background with a colorless (what seems to be) shoe in it. That happens because we don’t have <strong>lightning </strong>in our scene. The material of the 3D model reacts to light, just as a planet does from the light of a star, and we need light to show it properly. Well makes sense. So to step <strong>6</strong>:</p><h4><strong>6. Add Light</strong></h4><p>There are <strong>six(6) </strong>kinds of lightsin three.js but we are going to use just two of them for this example:</p><ul><li><strong>Ambient Light </strong>— This light globally illuminates all objects in the scene.</li><li><strong>Directional Light </strong>— A ‘sun-like’ light that gets emitted in a specific direction.</li></ul><pre>// First parameter is the color of light; second is intensity of light.<br>const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);<br>const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);<br>// Finally we add Light to the Scene<br>scene.add(ambientLight, directionalLight);</pre><p>And now the updated canvas<strong>:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U0xbxJaW9VcP9XQXSxpzdQ.png" /><figcaption>Loaded Model With Lightning</figcaption></figure><p>Now what we need is a groundto properly reflect the light that comes from above, hits the shoe, and the ground at the same time while also displaying the shadow of the model.</p><p>To do that we have to create a <strong>mesh</strong>composed by a <strong>Plane Geometry.</strong></p><blockquote>A <strong>mesh</strong>in 3D graphics is an object composed of vertices, edges, and faces that define the shape of an object in 3D space, and it is composed of a <strong>geometry</strong>and <strong>material</strong>properties.</blockquote><h4><strong>7. Add a Plane Geometry.</strong></h4><pre><br>const planeMaterial = new THREE.MeshStandardMaterial( { color: params.material, specular: 0x101010 } );<br>const planeGeometry = new THREE.PlaneGeometry(50, 50);<br>const planeMesh = new THREE.Mesh(planeGeometry, material);<br><br>planeMesh.rotation.x = - Math.PI / 2;<br>planeMesh.position.y = - 0.5;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I4yRkQ5mh_z8UvgDndozOQ.png" /><figcaption>Object on a Plane</figcaption></figure><p>By default a plane geometry is created vertically at the center of the screen. So we need to add some math for rotations, hence <strong>Math.PI / 2, </strong>in the <strong>x-axis </strong>to cause it to spin 90 degrees in a clockwise direction when viewed from the top as seen in the picture.</p><h4>8. Next, the shadow.</h4><p>To project the shadowof the model in the plane we insert these new lines for the 3D Model, Plane Geometry and also the renderer:</p><pre>// ...<br>loader.load(<br>  &#39;shoePath&#39;, (gltfFile) =&gt; {<br><br>  // create a constant &quot;mesh&quot; to make it reusable<br>  const mesh = gltfFile.scene;<br>  mesh.castShadow = true;<br>  //... rest of the code<br><br>});<br><br>// ... at plane creation<br>planeMesh.receiveShadow = true;<br><br>//... at renderer<br>renderer.shadowMap.enabled = true;<br>renderer.shadowMap.type = THREE.PCFSoftShadowMap;</pre><p>After some modifications of the background, scene fog, and the plane geometry to style it better in the end we will see this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tLXV0RO5bXi-NxdGKGQ84Q.png" /><figcaption>Fully Loaded Model</figcaption></figure><p><strong><em>And that’s it!</em></strong> With just a few lines of code, you can display a 3D shoe on a web page and allow users to interact with it.</p><p>There is so much more to explore in <strong>WebGL</strong> and the possibilities for 3D graphics in web development are endless.</p><h4>While I cannot cover everything in this article, I will continue to share my experiences and insights on this topic in future, more advanced, articles.</h4><p>In the meantime, feel free to play around with the code I have provided in CodeSandBox &amp; StackBlitz and see what you can create. I have also added some helpers for you to control lightning and also use controls to move around the object on every angle.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fgithub%2Fegimata%2Fthreejs-web-dev%2Ftree%2Fmaster%2F%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark%26view%3Dpreview&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fp5ged7&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fp5ged7%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/a79063a58949c31dcda01644653d964a/href">https://medium.com/media/a79063a58949c31dcda01644653d964a/href</a></iframe><h4>StackBlitz:</h4><p><a href="https://stackblitz.com/edit/node-cgmgef?file=package.json,src%2Fscript.js">3D Web Development: Understanding WebGL for Interactive 3D Graphics - StackBlitz</a></p><p><em>Stay tuned</em> for more updates, and you can reach out if you have any specific topics or questions you’d like me to cover. I’m always happy to help and share my experience with WebGL, Three.js, and more!</p><h4>If you liked this article don’t hesitate to follow and leave a clap!</h4><p><em>See you on the next one..</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0a38c6c8a3d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web Development for Beginners: A Step by Step Guide]]></title>
            <link>https://medium.com/thefreshwrites/web-development-for-beginners-a-step-by-step-guide-34f96d4254bf?source=rss-bdda66ff4bf5------2</link>
            <guid isPermaLink="false">https://medium.com/p/34f96d4254bf</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[beginner]]></category>
            <dc:creator><![CDATA[Egi Mata]]></dc:creator>
            <pubDate>Sat, 28 Jan 2023 17:03:57 GMT</pubDate>
            <atom:updated>2023-02-14T15:18:33.945Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7sHwLsqir4JQU6kmmZ63sw.jpeg" /><figcaption>Web Development — Step by Step Guide</figcaption></figure><p>Recently had a friend of mine ask me how to get started with programming and the softwares to have on his laptop to begin learning web development. As someone who has been in the field for a while, I understand how overwhelming it can be to start from scratch since now there are thousands of courses, articles and it’s a constantly evolving field.</p><p>However, with the right guidance and resources, anyone can learn the basics of web development and start building their own websites.</p><p><strong><em>When you are first learning programming, there is no “easy” language to choose.</em></strong></p><p>Basically you have to start from somewhere, may that be for you PHP, Python, for some others C, C++, JavaScript, Go, or whatever, the key point is to learn, not just syntax but problem-solving skills.</p><p>In this article, I will walk you through the essential steps and tools needed to begin your journey in web development. From learning the core technologies of <strong>HTML</strong>, <strong>CSS</strong>, and <strong>JavaScript</strong>, to understanding the importance of coding.</p><p>Just by focusing on these 3 <strong>fundamentals </strong>you will be impressed of what you can build.</p><p>Before I begin explaining how these work, you need to have a couple of things in your PC/laptop.</p><h4>First of all you need <a href="https://nodejs.org/en/">Node.Js</a>.</h4><p>It’s the JavaScript runtime environment. Basically you will need it the most when you will start working with frontend/backend JavaScript Frameworks. But either way it is important to have it in your machine for later use.</p><h4>Next: You need a text editor.</h4><p>Get Familiar with a Text Editor like:</p><p>- <a href="https://code.visualstudio.com/"><strong>Visual Studio Code,</strong></a><strong><br>- </strong><a href="https://www.sublimetext.com/"><strong>Sublime</strong></a><strong>, <br>- </strong><a href="https://atom.en.uptodown.com/windows"><strong>Atom</strong></a><strong>.</strong></p><p>They are <strong>free </strong>and just basic software that you’ll use to write the code for your projects. These text editors have features like syntax highlighting, code completion, and debugging tools that make it easier to write and debug code.</p><p>I would suggest to go with <strong>VS Code</strong>, since it is more popular with a large active community and has an easy-to-use interface. Also comes with integrated Git support and a wide array of extensions for more functionalities.</p><h4>You need a local server.</h4><p>In order for you to test your code in relation to a <strong>database </strong>(where you will store most of web information) you would need a <strong>local server </strong>on your pc/laptop:</p><ul><li><a href="https://www.wampserver.com/en/">WampServer</a></li><li><a href="https://www.apachefriends.org/">XAMPP</a></li></ul><p>At the begining it might be a bit confusing configuring them, but there are many articles on how to properly use them, or even on their website. Basically you install it, start the server and you will have phpMyAdmin tool installed using <strong>MySQL</strong> or <strong>MariaDb </strong>as a database.</p><p>In order to stay within the scope of this article, I will not delve into all the details of this topic.</p><h4>Finally: You need Webpack.</h4><p>Webpack is a module bundler that takes all of your <strong>JavaScript </strong>and other assets, such as images and CSS, and bundles them into a single file or a few files.</p><p>It allows you to use modern JavaScript features and optimizes your code for production.</p><p>It’s not something you install on your machine, but you install it inside your project to bundle it.<br>To install webpack, you need to have <strong>Node.js </strong>(mentioned above) and <strong>npm </strong>(<strong>Node Package Manager</strong>) installed on your computer.</p><p>Then, you can use the following command in your text editor’s terminal:</p><pre>npm install webpack webpack-cli --save-dev</pre><p>If you are using Windows, you can install <a href="https://gitforwindows.org/"><strong>GitBash</strong></a>, to run linux commands.</p><p><strong>1. HTML (Hypertext Markup Language)</strong> is used to create the structure of a web page.</p><p>I have been in this field for a long time, and sometimes you may get the idea that HTML is not that important, or it’s very easy as you will learn it fast, and that’s true. But it doesn’t mean that you won’t use it much. In web development, especially if you decide to become a frontend developer, you will use it all the time.</p><p>The base structure of a website is composed by:<br>- <strong>header </strong>-&gt; where the menu/navigation is located<br>- <strong>body </strong>-&gt; where all the content of a page in the website is placed<br>- <strong>footer </strong>-&gt; mostly here are helping links, contacts and social media icons (sometimes even google maps);</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>  &lt;head&gt;<br>      &lt;title&gt;This is a basic HTML template Starter&lt;/title&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;<br>      &lt;div&gt;<br>          &lt;h1&gt;Welcome to my website&lt;/h1&gt;<br>          &lt;p&gt;This is a simple webpage created using HTML.&lt;/p&gt;<br>      &lt;/div&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>2. CSS (Cascading Style Sheets) </strong>is used to style the page.</p><p>There are many ways to style the page. For example we can style the HTML created above by:<br><strong>a)</strong> providing <strong>classes </strong>within it’s paragraphs, headers, div-s, and edit styling based on those classes:</p><pre>//previous code ...<br>&lt;div class=&quot;container&quot; &gt;<br>    &lt;h1&gt;Welcome to my website&lt;/h1&gt;<br>    &lt;p&gt;This is a simple webpage created using HTML.&lt;/p&gt;<br>&lt;/div&gt;</pre><p>and to style it in a css file (<strong><em>sample.css</em></strong>):</p><pre>.container {<br>  /* we set the width and height of the container to 100% */<br>  width: 100%;<br>  height: 100%<br>}</pre><p><strong>b) </strong>by selecting directly the <strong>tag </strong>you want to edit:</p><pre>h1 {<br>  color: blue;<br>}<br>p {<br>  font-size: 18px;<br>}</pre><p>Or by simply adding a style instead of class inside tag component:</p><pre>&lt;!-- previous code ... --&gt;<br>&lt;div style=&quot;width: 100%; height: 100%;&quot; &gt;<br>    &lt;h1&gt;Welcome to my website&lt;/h1&gt;<br>    &lt;p&gt;This is a simple webpage created using HTML.&lt;/p&gt;<br>&lt;/div&gt;</pre><p>There are also many CSS Frameworks, such as Bootstrap, Tailwind, wich can help you with the design so you don’t have to code everything from scratch. But I strongly advice to start first from the very basics so you wont get stuck when things get more complicated.</p><p><em>“I remember once when I first started learning, I spent 2 hours finding out why a container with information inside wasn’t showing on the screen. It was by mistake I found out about </em><strong><em>‘z-index’ </em></strong><em>property, which is used to specify the stack order of elements. It determines the order in which elements are stacked on top of each other, with elements having a higher z-index value appearing on top of those with a lower z-index</em> value.”</p><p><strong>3) JavaScript </strong>is a programming language that is used to add <strong>interactivity </strong>to webpages. It allows you to create <strong>dynamic </strong>web pages by adding features such as:<br>- various animations,<br>- form validation,<br>- image sliders,<br>- modal windows, and so much more.</p><p>JavaScript can be used also to interact with the server (if you are working on backend).</p><p>We can add interactivity to the webpage for example by adding a button that changes the text color when clicked:</p><pre>&lt;button onclick=&quot;changeColor()&quot;&gt;Change Color&lt;/button&gt;<br>&lt;script&gt;<br>  function changeColor() {<br>    const text = document.getElementsByTagName(&quot;p&quot;);<br>    text[0].style.color = &quot;red&quot;;<br>  }<br>&lt;/script&gt;</pre><p>When we are coding in pure JavaScript, we need to add the functionalities inside <strong><em>&lt;script&gt;&lt;/script&gt; </em></strong>tags. <br>The proper way is to create a new file “<strong><em>newFile.js” </em></strong>with JS code inside, and load this file between the script tags above.</p><p>You may notice in the begining that some files or variables are named “<strong>new_file.js<em>”, “</em>new-file.js<em>”, </em></strong>or <strong><em>“</em>newVariable<em>”. </em></strong>These are called naming conventions. There are a few:</p><ul><li><strong>Camel Case</strong>: combines words together, with the first letter of each word being capitalized except the first one: firstName, getUserData, newFile.js.</li><li><strong>Pascal Case</strong>: similar to Camel Case, but the first letter of every word is capitalized: FirstName<em> </em>or GetUserData.</li><li><strong>Snake Case</strong>: separates words using underscores, all letters are in lowercase: first_name<strong><em> </em></strong>or get_user_data.</li><li><strong>Kebab Case</strong>: Similar to Snake Case, words are separated by hyphens, all letters are in lowercase first-name or get-user-data.</li></ul><p>In short, JavaScript is a powerful and versatile programming language. It may not be the easiest language to learn, but with a bit of <em>patience </em>and <em>determination</em>, you’ll be creating interactive and dynamic web applications in no time.</p><p>When I started learning programming, I remember feeling a bit overwhelmed by all the different languages and concepts. But once I started diving into JavaScript, it all started to make sense. I remember thinking: “<em>This is it! This is the language that’s going to take my career to the next level”</em>.</p><p>There are also a lot of books you can start learning:</p><p>- <strong><em>You Don’t Know Javascript — Kyle Simpsons,<br>- A Smarter Way to Learn JavaScript — Mark Myers,<br>- Secrets of the JavaScript Ninja, etc.</em></strong></p><p>or by following online courses on <strong>Udemy </strong>or <strong>crash courses </strong>on YouTube.</p><p>On top of this I have to add that no matter how many courses you watch, never focus only on the syntaxes or memorizing everything.</p><p>There will come a time where you won’t watch anymore courses, or maybe just watch some parts to recap old stuff. The real deal of fixing problems is the <strong>DOCUMENTATION (</strong>or StackOverflow, nowdays chatGPT, or bothering your seniour dev friend every 5 mins) which no one likes to read at the begining.</p><p>I can’t emphasize this enough, but <strong>Documentation </strong>is really important and most of frameworks, libraries, have a really well documented page with real examples that can lead you to solving your problems.</p><p>It’s not always going to be fun and exciting with coding, most of the times <strong><em>i</em>t involves a lot of reading and practice<em>. </em></strong>But when you’ve honed your skills and bring your product to life, the sense of accomplishment and satisfaction is truly indescribable.</p><p>Doesn’t matter if you have 1 month, 1 year or <strong>10 years</strong> of experience, you will always google: “<em>how to center a div using css</em><strong>”</strong>.</p><p>What I mean by this is that memorizing code is not always be necessary. It is crucial to have a solid understanding of the foundations and the ability to <strong>think logically </strong>and <strong>critically </strong>about the problem at hand. This includes understanding the overall <strong>architecture</strong>, as well as having the ability to research and understand new concepts as needed.</p><blockquote>By having a clear mind of what you want to do you will also find it easier to google your questions with the right keywords.</blockquote><h4>The key is to focus on understanding the underlying concepts and how they work together, rather than just memorizing syntax.</h4><p>It’s normal to question whether you’ve chosen the right language to begin with, but the important thing to remember is that you are learning more than just syntax — you are learning new <strong>concepts</strong>, <strong>approaches</strong>, <strong>developing a new way of thinking about problem-solving</strong>, and how to tie it all together.</p><p>Now we go to the next point, after learning HTML, CSS, JS, you want to use a data storage system to store information. In this step you need to:</p><p><strong>4) Learn a Database Management System</strong></p><p>In order to store and retrieve data, you’ll need to learn a database management system like <strong>MySQL</strong>, <strong>MongoDB</strong>, or <strong>SQLite</strong>. These databases can be used to store and retrieve information about users, products, or any other data that needs to be saved and retrieved.</p><p><strong>Relational databases</strong> like MySQL and SQLite use tables and rows to store data, while <strong>non-relational databases</strong> like <strong>MongoDB</strong> use collections and documents (mostly written in JSON format).</p><p>In the end it’s important to remember that you’re not alone in this field. There are countless resources available online, as well as a vibrant community of fellow web developers who are more than happy to help and support you.</p><p>If you enjoyed reading this article and would like to learn more about web development, please consider <strong>following</strong> me on Medium.</p><p>I will continue to write more advanced articles with more “<em>in-depth” </em>information on the different aspects of web development as I cannot write everything in just one article.</p><p>While I share my previous experiences and mistakes, I want to help you avoid the same pitfalls that I encountered on my journey.</p><p>Thanks for reading and remember to <strong><em>Practice, Practice, Practice</em></strong>…</p><p>See you on the next one!</p><p>Thanks for reading.Happy learning 😄</p><p>Do support our publication by following it</p><ul><li><a href="https://medium.com/thefreshwrites">The Fresh Writes</a></li><li><a href="https://medium.com/thefreshwrites/java-concurrent-api-packages-semaphore-5f3e7a11aa50">Semaphore | Java Concurrent API</a></li><li><a href="https://medium.com/thefreshwrites/java-concurrent-api-packages-part-1-a0c204a6afda">Java Concurrent API Packages — Part 1</a></li><li><a href="https://medium.com/thefreshwrites/java-8-bifunction-biconsumer-bipredicate-interface-with-example-5341009caf66">Java — 8 | BiFunction, BiConsumer &amp; BiPredicate Interface with Example</a></li><li><a href="https://medium.com/thefreshwrites/10-dev-tools-for-development-in-react-to-code-like-a-pro-part-2-7bf729dfb280">10 Dev Tools for Development in React to Code like a Pro — Part 2</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34f96d4254bf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thefreshwrites/web-development-for-beginners-a-step-by-step-guide-34f96d4254bf">Web Development for Beginners: A Step by Step Guide</a> was originally published in <a href="https://medium.com/thefreshwrites">The Fresh Writes</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Single-Threaded Nature of JavaScript/Typescript: Async Programming]]></title>
            <link>https://javascript.plainenglish.io/the-single-threaded-nature-of-javascript-typescript-async-programming-d4302b15abcd?source=rss-bdda66ff4bf5------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4302b15abcd</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[asynchronous-programming]]></category>
            <category><![CDATA[asynchronous-javascript]]></category>
            <dc:creator><![CDATA[Egi Mata]]></dc:creator>
            <pubDate>Fri, 20 Jan 2023 12:00:54 GMT</pubDate>
            <atom:updated>2023-04-05T14:48:36.162Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*zcBn96fgMc0Lv5_9zsNREA.png" /></figure><p>On my <a href="https://medium.com/@egi.mata1/why-typescript-is-a-must-have-for-any-javascript-developer-insights-from-you-dont-know-518416f606c">first article</a> I wrote about some of the differences between JS and TS.</p><p>Now we are going to explore the <strong>async </strong>nature as a single threaded language.</p><p>In JavaScript &amp; TypeScript, the <strong>single-threaded</strong> nature means that only one task can be executed at a given time.</p><p>On the other hand <strong>async programming</strong> refers to the ability of the language to perform tasks asynchronously, allowing the main thread of execution to continue running while waiting for other tasks to complete. This is achieved through the use of <strong><em>callbacks</em></strong>, <strong><em>events</em></strong>, <strong><em>promises</em></strong> and <strong><em>async</em></strong>/<strong><em>await</em></strong>.</p><p>Before I begin explaining these in coding terms, I would like to talk about a very interesting reference of how async tasks of a single-threaded language is very similar to our brain when we try to do <strong>multitasking</strong>.</p><p>In this section I will summarize a long text / chapter written from Kyle Simpson in his book “You Dont Know Javascript” about the connection of <strong><em>Sequential Brain </em></strong>with asynchronization. If you are interested only on the coding part of how it works, you can skip this part.</p><p>“<em>I’m pretty sure most of you have heard someone say (even made the claim yourself), “</em><strong><em>I’m a multitasker.</em></strong><em>”<br>But are we multitaskers? Can we really do two conscious, intentional actions at once and think/reason about both of them at exactly the same moment? Does our highest level of brain functionality have parallel multithreading going on?</em></p><p><em>The answer may surprise you which is: </em><strong><em>probably not.</em></strong></p><p><em>That’s just not really how our brains appear to be set up. We’re much more single taskers than many of us would like to admit. We can really only think about one thing at any given instant.</em></p><p><em>I’m not talking about all our involuntary, subconscious, automatic brain functions, such as heart beating, breathing, and eyelid blinking. Those are all vital tasks to our sustained life, but we don’t intentionally allocate any brain power to them.”</em></p><p>According to Simpson, humans are not capable of truly multitasking in the same way that a computer can. While it is true that the human brain can process multiple tasks simultaneously, it is not able to give equal attention to all tasks at once. Instead, we rapidly switch our attention between tasks, much like a single threaded program can only execute one task at a time.</p><p><em>Thankfully, while we obsess about checking social network feeds for the 15th time in three minutes, our brain carries on in the background (threads!) with all those important tasks.</em></p><p><em>When we fake multitasking, such as trying to type something at the same time we’re talking to a friend or family member on the phone, what we’re actually most likely doing is acting as </em><strong><em>fast context switchers</em></strong><em>. In other words, we switch back and forth between two or more tasks in rapid succession, simultaneously progressing on each task in tiny, fast little chunks. We do it so fast that to the outside world it appears as if we’re doing these things in parallel.</em></p><p><em>Does that sound like </em><strong><em>async evented concurrency </em></strong><em>(just like what happens in JS) to you?!</em></p><p><em>There’s a big, observable difference between how we plan various tasks, and how our brains actually operate those tasks.<br>Even though at an operational level our brains are async evented, we seem to plan out tasks in a sequential, synchronous way. “I need to go to the store, then buy some milk, then drop off my dry cleaning.”</em></p><p><em>Can you actually imagine having a line of thinking that plans out your to-do errands like this:</em></p><blockquote>“<strong>I need to go to the store (1), </strong>but on the way I’m sure<strong> I’ll get a phone call (2)</strong>, so ‘Hi, Mom’, and while she starts talkin, <strong>I’ll be looking up the store address (3) </strong>on GPS, but that’ll take a second to load, so <strong>I’ll turn down the radio (4) </strong>so I can hear Mom better … <br>then<strong> I’ll realize I forgot to put on a jacket (5) </strong>and it’s cold outside, but no matter, keep driving and talking to Mom …<br>and then the seatbelt ding <strong>reminds me to buckle up (6)</strong>, so ‘Yes, Mom, I am wearing my seatbelt, I always do!’. Ah, finally:</blockquote><blockquote>the GPS got the directions, now…”</blockquote><p>As ridiculous as that sounds as a formulation for how we plan our day out and think about what to do and in what order, nonetheless it’s exactly how our brains operate at a functional level. But remember, that’s not multitasking, it’s just fast context switching.</p><p>With this in mind, let’s take a closer look at how async programming works in JavaScript.</p><h4><strong>Now to coding</strong>:</h4><p>There are several ways to perform async programming in JavaScript/Typescript, as I mentioned in the beginning of this article, including using: <strong>Callbacks</strong>, <strong>Events, Promises, Async/Await.</strong></p><ul><li><strong>A callback </strong>is a function that is passed as an argument to another function and is executed after the outer function has completed. For example:</li></ul><pre>function greet(name, callback) {<br>  console.log(`Hello, ${name}!`);<br>  callback();<br>}<br><br>function sayGoodbye() {<br>  console.log(&quot;Goodbye!&quot;);<br>}<br><br>greet(&quot;John&quot;, sayGoodbye);<br>// Output: &quot;Hello, John!&quot;<br>// Output: &quot;Goodbye!&quot;</pre><p>The <strong>greet</strong> function takes a <strong>name </strong>and a <strong>callback function </strong>as arguments. The <strong>greet </strong>function logs a message with the provided name and then calls the callback function. Then the <strong>sayGoodbye </strong>function is passed as a callback to the <strong>greet </strong>function and is executed after the <strong>greet </strong>function has finished.</p><ul><li>An <strong>event </strong>is a signal that something has happened, and a listener is a function that is executed in response to that event. For example:</li></ul><pre>const button = document.querySelector(&quot;button&quot;);<br><br>button.addEventListener(&quot;click&quot;, () =&gt; {<br>  console.log(&quot;Button was clicked!&quot;);<br>});</pre><p>In the example above, a listener function is added to the click event of a button element. When the button is clicked, the listener function is executed and it will log into the console “<em>Button was clicked!</em>”.</p><ul><li>A <strong>promise</strong> represents the result of an async operation, and can be either resolved (successful) or rejected (failed), just like real life promises; when you make a promise you either keep (resolve) it or don’t (reject). <br>Promises can be used to simplify the process of chaining async operations together. For example:</li></ul><pre>const promise = new Promise((resolve, reject) =&gt; {<br>  setTimeout(() =&gt; {<br>    resolve(&quot;Completed Async Task&quot;);<br>  }, 1000);<br>});<br><br>promise.then((result) =&gt; {<br>  console.log(result);<br>});<br>// Output: &quot;Async task completed&quot; (after 1 second)</pre><p>In this example, a promise is created that will resolve with the message “<em>Completed Async Task</em>” after a 1-second delay. The <strong>then </strong>method of the promise is used to specify a callback that will be executed when the promise is resolved.</p><ul><li><strong>Async/await:</strong> a feature of JavaScript that allows the use of async/await syntax to make async code look and behave like synchronized code. Async/await is built on top of promises and makes it easier to work with async code.</li></ul><pre>async function greet(name) {<br>  return `Hello, ${name}!`;<br>}<br><br>async function main() {<br>  const greeting = await greet(&quot;John&quot;);<br>  console.log(greeting);<br>}<br><br>main();<br>// Output: &quot;Hello, John!&quot;</pre><p>The <strong>greet </strong>function is marked as <strong>async </strong>and returns a promise. The <strong>main </strong>function is also marked as <strong>async </strong>and uses the <strong>await </strong>keyword to wait for the <strong>greet </strong>function to resolve before logging the result.</p><p>In other words, async programming in JavaScript and TypeScript can provide a similar experience to multitasking by allowing the main thread of execution to continue running while waiting for other tasks to complete.</p><p>Overall, async programming allows for the execution of multiple tasks while maintaining the single-threaded nature of the language. It allows for a more responsive and efficient program by allowing the main thread to continue running while waiting for other tasks to complete.</p><p>If you like this content don’t hesitate to follow. There are many more projects at hand on which I am planning to write about in the near future. Until then,</p><p>Thank you for reading!</p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>.</em></p><p><em>Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></p><p><strong><em>Interested in scaling your software startup</em></strong><em>? Check out </em><a href="https://circuit.ooo/?utm=publication-post-cta"><strong><em>Circuit</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4302b15abcd" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/the-single-threaded-nature-of-javascript-typescript-async-programming-d4302b15abcd">The Single-Threaded Nature of JavaScript/Typescript: Async Programming</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web Development Workflow Essentials: How to Stay Organized and Productive]]></title>
            <link>https://medium.com/@egimata/web-development-workflow-essentials-how-to-stay-organized-and-productive-aac53ddde68f?source=rss-bdda66ff4bf5------2</link>
            <guid isPermaLink="false">https://medium.com/p/aac53ddde68f</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[testing-tools]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[workflow-management]]></category>
            <dc:creator><![CDATA[Egi Mata]]></dc:creator>
            <pubDate>Thu, 12 Jan 2023 20:01:06 GMT</pubDate>
            <atom:updated>2023-01-13T17:14:43.283Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*myHsckPnIPebKXH-Zp10Gw.png" /></figure><p>Staying organized and productive as a web developer is key to delivering high-quality projects on time. With so many moving pieces and tasks to manage, it can be easy to get overwhelmed and lose track of what needs to be done and sometimes you may lose your way. In this post, we’ll explore some essential tools and practices that can help you streamline your workflow and stay on top of your projects.</p><blockquote><strong>1. Use a project management tool</strong></blockquote><p>One of the first steps to take when setting up your web development workflow is to choose a project management tool.</p><p>A project management tool allows you to keep track of tasks, deadlines, and team members in one place. It can help you stay organized and prioritize your work, and can also be a useful communication and collaboration tool for remote teams.</p><p>There are many options available, ranging from simple to-do lists to more comprehensive project management platforms. Some popular choices for web developers include <strong>Asana</strong>, <strong>Trello</strong>, and <strong>JIRA</strong>.</p><p>I used to use Asana and Trello for a long time, then after switching between jobs I also started switching tools. At my current job we are keeping track of projects progress simply using GitHub Issues.<br>Using GitHub Issues can be a helpful way to keep track of tasks and communicate with your team or clients.</p><p>In the end its just a matter of what your team uses, but having a general knowledge of how each of these tools work can be very helpful in the future.</p><blockquote><strong>2. Use version control system</strong></blockquote><p>Another essential tool for web developers is a version control system like <strong>Git</strong>.</p><p>Version control allows you to track and manage changes to your codebase, making it easier to roll back to previous versions if necessary. It also enables you to collaborate with other developers on the same codebase, making it easier to merge changes and resolve conflicts in the code of your application. Also helps you keep track of what has been changed and when, making it easier to roll back to previous versions if you mess ‘<strong>stuff</strong>’ up.</p><p>Not to say ‘if’ but ‘when’ you do (we all do, it’s normal) you can use <a href="https://ohshitgit.com/"><strong>Oh Shit Git</strong></a>. It is a very useful website showing mostly every scenario when you encounter some bad situations and how revert or prevent it from happening. So never really panic when it comes to programming (unless you publish in production without testing the stuff).</p><blockquote><strong>3. Use a linter and formatter</strong></blockquote><p>A linter is a tool that checks your code for syntax errors and style issues, helping you catch mistakes and improve the overall quality of your code. A formatter is a tool that automatically formats your code to adhere to a specific style guide, making it easier to read and maintain.</p><p>A linter helps you keep the code in the same structure throughout the applcation, especially when you have a team of more than two people working on it. By linting, all the developers keep tha same code structure, without errors.</p><p>Using a linter and formatter can save you time and frustration by helping you catch issues early on and ensuring that your code is consistent and easy to read. Some popular linters for web development include ESLint and JSHint, and popular formatters include Prettier and Beautify.</p><blockquote><strong>4. Use testing and debugging tools</strong></blockquote><p><strong>Testing and debugging</strong> are VERY important steps in the web development process, and having the right tools can make a big difference in your productivity.</p><p>Some tools that can be helpful for testing include unit testing frameworks like Jest and Mocha, and browser testing tools like Selenium and Cypress. Also some debugging tools like the browser developer console and debugging libraries like the React Developer Tools can help you identify and fix issues in your code. Using these tools can save you time and help you deliver higher-quality code.</p><p><strong>Testing</strong> is often viewed as a tedious and time-consuming task. Despite this, testing is crucial for ensuring the quality and reliability of your code. I didn’t use to believe in testing when I first started programming.</p><p>I get it, mostly we want to focus on the main quest, which is developing and implementing ‘<em>that feature</em>’ you impatiently want to develop. But sometimes you have to finish some of the side quests to become really good at the main one.</p><ul><li><strong>It helps catch bugs and errors early on</strong></li></ul><p>It allows you to identify and fix issues in your code before they become a problem. By running tests regularly, you can catch mistakes and errors early on, which can save you time and frustration in the long run.</p><ul><li><strong>It ensures that your code works as intended</strong></li></ul><p>Testing allows you to verify that your code is functioning correctly and meeting the requirements of the project. This is especially important when working on larger or more complex projects, where a single error can have serious consequences.</p><p>I focus a lot on this topic, mostly because of its underrated importance. While testing may not be the most exciting part of the process, it is an essential step that should not be <strong>overlooked</strong>. By taking the time to test your code thoroughly, you can save yourself headaches and deliver better results to your clients.</p><p>Finally, by adopting these tools and practices, you can create a streamlined and efficient workflow that helps you stay organized and productive as a web developer. Remember to choose the tools and practices that work best for you and your team — the key is to find a balance that allows you to work effectively without adding unnecessary complexity.</p><p>Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aac53ddde68f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Typescript is a Must-Have for Any JavaScript Developer: Insights from ‘You Don’t Know…]]></title>
            <link>https://medium.com/@egimata/why-typescript-is-a-must-have-for-any-javascript-developer-insights-from-you-dont-know-518416f606c?source=rss-bdda66ff4bf5------2</link>
            <guid isPermaLink="false">https://medium.com/p/518416f606c</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Egi Mata]]></dc:creator>
            <pubDate>Thu, 05 Jan 2023 18:59:02 GMT</pubDate>
            <atom:updated>2023-01-13T17:13:44.010Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why Typescript is a Must-Have for Any JavaScript Developer: Insights from ‘You Don’t Know JavaScript’</h3><figure><img alt="Why Typescript is a Must-Have for Any JavaScript Developer" src="https://cdn-images-1.medium.com/max/1024/1*RTBWhc29fyo1FGIVwxgGUw.jpeg" /></figure><p>I’m excited to share my thoughts on a topic that has has always fascinated me, has had a significant impact on my career and improving my workflow as a developer: TypeScript.</p><p>Considering this is my first blog post about programming I hope that by sharing my insights, I can provide a unique perspective on this subject.</p><p>Typescript is a superset of JavaScript that adds optional static typing and other features to the language. It offers a number of benefits for JavaScript developers, including:</p><ul><li><strong>Improved error detection:<br></strong>Static typing enables you to catch errors at compile-time rather than runtime, reducing the risk of runtime errors.</li></ul><p>For example, consider the following code written in JavaScript:</p><pre>function add(a, b) {<br>  return a + b;<br>}<br><br>console.log(add(1, 2)); // 3<br>console.log(add(&quot;1&quot;, 2)); // &quot;12&quot;</pre><p>In the code above, the add function is supposed to take in two numbers and return their sum. However, if we pass in a string for the a parameter, the function will still run and return a concatenated string, &quot;12&quot;, rather than throw an error. This can be problematic because it can lead to unexpected behavior in the program.</p><p>Now consider the same code written in TypeScript:</p><pre>function add(a: number, b: number): number {<br>  return a + b;<br>}<br><br>console.log(add(1, 2)); // 3<br>console.log(add(&quot;1&quot;, 2)); // Error: Argument of type ‘string’ is not assignable to parameter of type &#39;number&#39;.</pre><p>In this version of the code, we have specified the types of the a and b parameters as number and the return type as number. As a result, when we attempt to pass in a string for the a parameter, the TypeScript compiler will throw an error because it is not a valid type for the a parameter.</p><p>This can help improve error detection because it allows developers to catch type errors before the code is even run, which can save time and effort in debugging.</p><ul><li><strong>Enhanced code readability and maintainability:</strong> Explicit type annotations make it easier to understand the purpose and behavior of your code, which can be especially useful when working on large or complex projects.</li></ul><p>Lets consider the following code written in JavaScript:</p><pre>function getUser(id) {<br>  return fetch(`/users/${id}`)<br>    .then(response =&gt; response.json())<br>    .then(user =&gt; {<br>      return {<br>        name: user.name,<br>        email: user.email<br>      };<br>    });<br>}<br><br>getUser(123).then(user =&gt; console.log(user.name));</pre><p>In this code, it is not immediately clear what the type of the user object is or what properties it has. This can make it difficult for developers to understand how the code is intended to be used and may lead to errors if the object is used in an unexpected way.</p><p>Now lets translate the same code written in TypeScript:</p><pre>interface User {<br>  name: string;<br>  email: string;<br>}<br><br>function getUser(id: number): Promise&lt;User&gt; {<br>  return fetch(`/users/${id}`)<br>    .then(response =&gt; response.json())<br>    .then(user =&gt; {<br>      return {<br>        name: user.name,<br>        email: user.email<br>      };<br>    });<br>}<br><br>getUser(123).then(user =&gt; console.log(user.name));</pre><p>In this version of the code, we have defined an User interface that specifies the shape of the user object, including the name and email properties. We have also annotated the id parameter as a number and the return type of the getUser function as a Promise of a User object. This makes it clear to developers what the types and structure of the user object should be, which can improve code readability and maintainability.</p><ul><li><strong>Improved learning tool:</strong> Typescript’s stricter syntax and helpful error messages can be helpful for beginners learning JavaScript, helping them to understand the underlying principles of the language and avoid common mistakes.</li></ul><p>As JavaScript developers, we’re no stranger to the fast-paced and constantly evolving world of front-end development. With new frameworks and libraries popping up all the time, it can be tough to keep up. This one tool that has gained a lot of traction in recent years is Typescript, a tool that adds optional static typing and other features to the language.</p><p><strong>But why should you care about Typescript?<br></strong>After all, JavaScript has been around for decades and has proven to be a versatile and powerful language.</p><p>In his book “<strong>You Don’t Know JavaScript</strong>”, author Kyle Simpson argues that Typescript is a game-changer for JavaScript developers, offering a number of benefits that can improve the quality and reliability of your code.</p><p>One of the main advantages of Typescript is that it enables you to catch errors at compile-time rather than runtime. With static typing, you can define the expected data types for variables, function arguments, and return values. This helps you catch mistakes early on and reduces the risk of runtime errors. As Simpson puts it, “TypeScript forces you to be more mindful of your code, which ultimately leads to better quality.”</p><p>Typescript also offers improved code readability and maintainability. With explicit type annotations, it’s easier for you and other developers to understand the purpose and behavior of your code. This can save time and frustration when working on large or complex projects.</p><p>But Typescript isn’t just for experienced developers — it can also be a helpful learning tool for beginners. By enforcing a stricter syntax and providing helpful error messages, Typescript can help you understand the underlying principles of JavaScript and avoid common pitfalls.</p><p>So, should you start using Typescript in all of your JavaScript projects? Not necessarily. Simpson advises that you should “<strong>use the right tool for the job.</strong>” But he also argues that Typescript is a valuable tool to have in your toolbox, and that every JavaScript developer should at least be familiar with it.</p><p>In conclusion, Typescript is a powerful and useful addition to the JavaScript ecosystem that offers a number of benefits for developers. Whether you’re a seasoned pro or just starting out, it’s worth considering adding Typescript to your workflow.</p><p>As Simpson writes, “TypeScript is the ‘professional’ way to write JavaScript.”</p><p>Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=518416f606c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>