<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Diego Augusto Antonioli Trevisan</title>
    <description>The latest articles on Forem by Diego Augusto Antonioli Trevisan (@diegoaatrevisan).</description>
    <link>https://forem.com/diegoaatrevisan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1220250%2F47c0d0e4-4820-433d-8c56-c69366e44b81.png</url>
      <title>Forem: Diego Augusto Antonioli Trevisan</title>
      <link>https://forem.com/diegoaatrevisan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/diegoaatrevisan"/>
    <language>en</language>
    <item>
      <title>Understanding TypeScript Primitive Types: Exploring Explicit and Implicit Typing</title>
      <dc:creator>Diego Augusto Antonioli Trevisan</dc:creator>
      <pubDate>Wed, 29 Nov 2023 01:23:35 +0000</pubDate>
      <link>https://forem.com/diegoaatrevisan/understanding-typescript-primitive-types-exploring-explicit-and-implicit-typing-1nmo</link>
      <guid>https://forem.com/diegoaatrevisan/understanding-typescript-primitive-types-exploring-explicit-and-implicit-typing-1nmo</guid>
      <description>&lt;p&gt;TypeScript, a superset of JavaScript, introduces static typing to the dynamically-typed world of JavaScript. This empowers developers to catch potential bugs during development and enhances code readability. In TypeScript, variables can be explicitly or implicitly typed, and the language supports various primitive types. Let's delve into each primitive type, explore examples, and understand the distinction between explicit and implicit typing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Primitive Types in TypeScript
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Number:&lt;/strong&gt;&lt;br&gt;
The &lt;code&gt;number&lt;/code&gt; type represents both integer and floating-point numbers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let count: number = 42;
let pi: number = 3.14;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. String:&lt;/strong&gt;&lt;br&gt;
The &lt;code&gt;String&lt;/code&gt; type is used for textual data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let message: string = "Hello, TypeScript!";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Boolean:&lt;/strong&gt;&lt;br&gt;
The &lt;code&gt;boolean&lt;/code&gt; type represents true or false values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let isCompleted: boolean = false;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Null and Undefined:&lt;/strong&gt;&lt;br&gt;
TypeScript has null and undefined as separate types.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let data: null = null;
let info: undefined = undefined;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Objects:&lt;/strong&gt;&lt;br&gt;
The &lt;code&gt;object&lt;/code&gt; type is a broad category encompassing non-primitive values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let user: object = { name: "John", age: 25 };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. Arrays:&lt;/strong&gt;&lt;br&gt;
Arrays can be typed using the &lt;code&gt;type[]&lt;/code&gt; syntax.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let numbers: number[] = [1, 2, 3, 4];
let fruits: string[] = ["apple", "banana", "orange"];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7. Tuple:&lt;/strong&gt;&lt;br&gt;
Tuples allow the declaration of arrays where the type of a fixed number of elements is known.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let person: [string, number] = ["John", 25];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;8. Enum:&lt;/strong&gt;&lt;br&gt;
Enums are a way of giving more friendly names to sets of numeric values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;enum Color {
    Red,
    Green,
    Blue
}
let myColor: Color = Color.Green;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  &lt;strong&gt;Explicit Typing:&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Explicit typing involves declaring the type of a variable during its initialization.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let age: number = 25;
let username: string = "JohnDoe";
let isActive: boolean = true;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explicit typing offers clarity and helps catch errors during development. However, it requires more keystrokes and can be redundant in simple cases.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Implicit Typing:&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Implicit typing, also known as type inference, allows TypeScript to deduce the type based on the value assigned.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let age = 25;           // TypeScript infers 'number'
let username = "John";  // TypeScript infers 'string'
let isActive = true;     // TypeScript infers 'boolean'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Implicit typing reduces verbosity, making code more concise. However, it may lead to less clarity, especially in larger codebases.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Understanding primitive types in TypeScript and when to use explicit or implicit typing is crucial for writing robust and maintainable code. Explicit typing provides clarity and catches errors early, while implicit typing promotes concise code. Striking the right balance depends on the context and developer preferences. By leveraging the strengths of both approaches, developers can harness the full power of TypeScript in their projects.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>programming</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Exploring JavaScript Functions: Normal Functions, Arrow Functions, and Generation Functions</title>
      <dc:creator>Diego Augusto Antonioli Trevisan</dc:creator>
      <pubDate>Mon, 27 Nov 2023 23:02:56 +0000</pubDate>
      <link>https://forem.com/diegoaatrevisan/exploring-javascript-functions-normal-functions-arrow-functions-and-generation-functions-1752</link>
      <guid>https://forem.com/diegoaatrevisan/exploring-javascript-functions-normal-functions-arrow-functions-and-generation-functions-1752</guid>
      <description>&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;In the dynamic realm of JavaScript, functions are fundamental building blocks that empower developers to organize and execute code efficiently. Understanding the nuances between normal functions, arrow functions, and the relatively newer concept of generator functions is crucial for writing clean, concise, and effective code. In this Article, we'll delve into each type of function, exploring their syntax, behavior, ad use cases.&lt;/p&gt;




&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Normal Function:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Normal functions, also known as traditional functions or function declarations, have been a staple in JavaScript since its early days. They follow a straightforward syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function add(a, b) {
  return a + b;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Key characteristics of normal functions include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Function Keyword:&lt;/strong&gt; They begin with the function keyword, followed by the function name.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hoisting:&lt;/strong&gt; Normal functions are hoisted, meaning they can be called before they are declared in the code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;this&lt;/code&gt; Binding:&lt;/strong&gt; The value of this inside a normal function is dynamically determined at runtime, depending on how the function is called.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Usage of normal functions is ubiquitous and appropriate for various scenarios, making them an essential part of JavaScript development.&lt;/p&gt;




&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Arrow Functions:&lt;/strong&gt;
Arrow functions, introduced in ECMAScript 6 (ES6), provide a more concise syntax compared to normal functions. They are especially favored for short, one-line expressions. The syntax for an arrow function is as follows:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const add = (a, b) =&amp;gt; a + b;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Key features of arrow functions include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No &lt;code&gt;function&lt;/code&gt; Keyword:&lt;/strong&gt; Arrow functions use a more concise syntax, omitting the need for the function keyword.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lexical Scoping:&lt;/strong&gt; They inherit the this value from the enclosing scope, which can be advantageous in certain situations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No Binding of &lt;code&gt;this&lt;/code&gt;, &lt;code&gt;arguments&lt;/code&gt;, &lt;code&gt;super&lt;/code&gt;, or &lt;code&gt;new.target&lt;/code&gt;:&lt;/strong&gt; Arrow functions do not have their own bindings for these values.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Arrow functions are particularly beneficial in scenarios where brevity and lexical scoping are crucial, such as in callback functions and functional programming paradigms.&lt;/p&gt;




&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Generator Functions:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Generator functions are a distinctive type of function in JavaScript designed for creating iterators. They enable pausing and resuming the execution of a function, allowing for more flexible control flow. The syntax for a generator function is denoted by an asterisk (*):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function* generateSequence() {
  yield 1;
  yield 2;
  yield 3;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Key characteristics of generator functions include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;yield&lt;/code&gt; Keyword:&lt;/strong&gt; Generator functions use the yield keyword to pause the function's execution and return a value to the caller.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Iterator Protocol:&lt;/strong&gt; They automatically implement the iterator protocol, enabling the use of &lt;code&gt;for...of&lt;/code&gt; loops.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Generator functions are useful for handling asynchronous operations, lazy evaluation, and scenarios where the efficient generation of a sequence of values is required.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In conclusion, understanding the differences between normal functions, arrow functions, and generator functions is crucial for writing effective JavaScript code. Each type of function serves specific use cases, and the choice between them depends on factors such as syntax preferences, scoping requirements, and the nature of the task at hand. As developers continue to explore and leverage the diverse features of JavaScript, mastering these function types becomes essential for crafting robust and maintainable code.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
