<?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>DEV Community: Leissan </title>
    <description>The latest articles on DEV Community by Leissan  (@leissan).</description>
    <link>https://dev.to/leissan</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%2F847590%2F755a3eda-b342-449c-b2e9-8b598fc998a8.jpeg</url>
      <title>DEV Community: Leissan </title>
      <link>https://dev.to/leissan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/leissan"/>
    <language>en</language>
    <item>
      <title>Context API (React)</title>
      <dc:creator>Leissan </dc:creator>
      <pubDate>Mon, 22 May 2023 13:36:11 +0000</pubDate>
      <link>https://dev.to/leissan/context-api-react-27n5</link>
      <guid>https://dev.to/leissan/context-api-react-27n5</guid>
      <description>&lt;p&gt;The Context API is a React structure that enables you to exchange unique details and assists in solving prop-drilling from all levels of your application. It is a React built-in feature, so we don’t have to worry about performance overhead and library installing issues. &lt;/p&gt;

&lt;p&gt;The React Context API is a way for a React app to effectively produce global variables that can be passed around. This is the alternative to "prop drilling" or moving props from grandparent to child to parent, and so on. When a project grows, data passing through props becomes more complicated, making the code more vulnerable and complex.  Context is also regarded as an easier, lighter approach to state management using Redux.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here are a few benefits of Context API that make it stand out:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; The Context API helps share data between components which you can’t easily share with props, for example, complex data objects.
&lt;/li&gt;
&lt;li&gt; React Context API provides a way to send data like userid, auth, and theme data through the component tree without sending any props manually at every level. &lt;/li&gt;
&lt;li&gt; We can also share specific states with multiple components instead through props manually. In some use cases, ideal for theming, localization, authentication etc.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  CONTEXT API VS USECONTEXT
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Context API&lt;/strong&gt;&lt;br&gt;
The Context API is the React feature used for solving props drilling problems. In Context API, we give data access to a component tree at the start to end level instead of using props. &lt;br&gt;
&lt;strong&gt;useContext&lt;/strong&gt;&lt;br&gt;
The useContext is the React built-in hook, used in context API to consume the context state or object. &lt;/p&gt;

&lt;p&gt;Context provides a way to share data between components without explicitly passing props at each level. By invoking the useContext function and passing the context object as an argument, we can access the context value within the component.&lt;/p&gt;

&lt;p&gt;To use the useContext hook, we need to follow two main steps: creating a context and consuming it in the desired components.&lt;br&gt;
We can create a context using the createContext function provided by React. This function returns an object with a Provider and a Consumer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ym17Yr1g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rpf3jmtzmgdg8y1ydyn3.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ym17Yr1g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rpf3jmtzmgdg8y1ydyn3.PNG" alt="Image description" width="648" height="56"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The createContext function optionally accepts a default value that will be used when no matching Provider is found in the component tree.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Provider: The Provider component is responsible for providing the context value to all the components that are descendants of it. It accepts a value prop, which can be any JavaScript value. This value will be made available to all the components that consume the context using the useContext hook.&lt;/li&gt;
&lt;li&gt; Consumer: The Consumer component is an optional way to consume the context value in class components or functional components where hooks are not available. It provides a render prop pattern, where the consumer component receives a function as a child. This function takes the context value as an argument and returns the JSX to render.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here's an example of how to create a context and use its Provider and Consumer components:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0o4LcNtm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1unedzbnad1so9tj9w7o.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0o4LcNtm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1unedzbnad1so9tj9w7o.PNG" alt="Image description" width="647" height="606"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While the Consumer component is still available for backward compatibility and for use in class components, the useContext hook provides a more concise and direct approach to consuming context values within functional components.&lt;br&gt;
Similarly, by using the useContext hook, we can directly access the context value without the need for a separate Consumer component:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--d1eFiRmk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ukmcmqkqiatarth1dkj.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--d1eFiRmk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ukmcmqkqiatarth1dkj.PNG" alt="Image description" width="651" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With the useContext hook, we can simplify the code and make it more readable by directly accessing the context value within the functional component.&lt;/p&gt;

&lt;p&gt;Overall, the createContext function in React enables us to create a context object that consists of a Provider and a Consumer. The Provider is responsible for providing the context value to its descendants, while the Consumer allows components to consume the context value using a render prop pattern. However, with the useContext hook, we can consume the context value directly within functional components, making the code more concise and easier to understand.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Active Record Validations</title>
      <dc:creator>Leissan </dc:creator>
      <pubDate>Sat, 01 Apr 2023 03:48:09 +0000</pubDate>
      <link>https://dev.to/leissan/active-record-validations-3op</link>
      <guid>https://dev.to/leissan/active-record-validations-3op</guid>
      <description>&lt;p&gt;Why are data validations important? We perform validations in order to ensure that only &lt;strong&gt;valid data&lt;/strong&gt; is saved into our database. It may seem as if data validation is a step that slows down our pace of work, however, it is an essential ingredient to our workflow rather than an additional step. &lt;/p&gt;

&lt;p&gt;We are doing so many important things online, like open bank accounts, sign into our student portals, check our flight status, etc., all of which are powered by data. And data validations are the most effective way to ensure data quality and integrity.&lt;/p&gt;

&lt;p&gt;As we know, Ruby on Rails is structured on the MVC architecture. The "M", also called the model layer, is responsible for managing how objects are created and stored in a database. In Rails, the model layer is run by Active Record by default, and as such, Active Record is responsible for handling the important task of data validation. Model-level validations protect our database, because they ensure that only valid data is saved there.&lt;/p&gt;

&lt;p&gt;What are some of the types of validations we can perform with Active Record? There  are some validations that come packaged with Active Record, and there are custom validations, that we can build ourselves. &lt;/p&gt;

&lt;h2&gt;
  
  
  Build-in Active Record Validations
&lt;/h2&gt;

&lt;p&gt;First of all, it’s important to know that not all methods trigger validation!&lt;/p&gt;

&lt;p&gt;The ones that &lt;strong&gt;trigger validation&lt;/strong&gt; are:&lt;br&gt;
• create&lt;br&gt;
• create!&lt;br&gt;
• save&lt;br&gt;
• save!&lt;br&gt;
• update&lt;br&gt;
• update!&lt;/p&gt;

&lt;p&gt;These ones &lt;strong&gt;do NOT trigger validation&lt;/strong&gt;:&lt;br&gt;
• decrement!&lt;br&gt;
• decrement_counter&lt;br&gt;
• increment!&lt;br&gt;
• increment_counter&lt;br&gt;
• insert&lt;br&gt;
• insert!&lt;br&gt;
• insert_all&lt;br&gt;
• insert_all!&lt;br&gt;
• toggle!&lt;br&gt;
• touch&lt;br&gt;
• touch_all&lt;br&gt;
• update_all&lt;br&gt;
• update_attribute&lt;br&gt;
• update_column&lt;br&gt;
• update_columns&lt;br&gt;
• update_counters&lt;br&gt;
• upsert&lt;br&gt;
• upsert_all&lt;/p&gt;

&lt;p&gt;There are numerous validation helpers we can use to validate different aspects of our data. We can use &lt;strong&gt;valid?&lt;/strong&gt; to trigger our validations and to return true if no errors were found in the object, and false otherwise. Let’s run through some examples.&lt;/p&gt;

&lt;p&gt;One of the most common situations we all have come across is to have a mandatory piece of data when we are filling out a form. For example, we want to make sure the user definitely inputs their &lt;em&gt;username&lt;/em&gt; in some form. This is how we would make sure that they do:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5lu9usawvga3heemjxz2.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5lu9usawvga3heemjxz2.PNG" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here we used a helper “presence” which – you guessed it! – ensures that a specific attribute is filled out. Easy and effective!&lt;/p&gt;

&lt;p&gt;What is we want to go a step further and make sure that not only they filled out their username, but that it is also unique? Here comes another helper, uniqueness:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx4ykhwu3v0phgkirvqvn.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx4ykhwu3v0phgkirvqvn.PNG" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If there is anything wrong with our data, there is a list of error messages saved when .valid? returns false. We can see these error messages through using the &lt;strong&gt;.error.messages&lt;/strong&gt; method. We can also use .invalid?, which is the reverse of the .valid? method. Let’s see that in action:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd2cliwqachdosj06kpw8.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd2cliwqachdosj06kpw8.PNG" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Errors.messages are extremely important, because they will tell us exactly what went wrong with our data. We can also check each attribute for errors separately, passing it as a key:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F62184slrbe1sr9p6z8vj.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F62184slrbe1sr9p6z8vj.PNG" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are a couple of important moments here. First of all, we can see that the validation does not trigger until we try to use a method which triggers validation, in this case – &lt;em&gt;save&lt;/em&gt;. There is no error message before we save! Secondly, we can see a specific error message related to an attribute we want to check, &lt;em&gt;:username&lt;/em&gt;, by running &lt;strong&gt;u.errors[:username]&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You can access a full list of validation helpers on &lt;a href="https://guides.rubyonrails.org/active_record_validations.html" rel="noopener noreferrer"&gt;Rails Guides&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Custom Validations
&lt;/h2&gt;

&lt;p&gt;We don’t have to limit ourselves to pre-built validations (although they are very useful!). Active Record gives us several easy ways to build custom validations, the most straight forward of which is to use a custom method to perform a validation. Let’s say we are building a website for travelers, and we want to make sure their favorite destination includes Brazil: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmgu0e2bkek7lp0ziwybt.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmgu0e2bkek7lp0ziwybt.PNG" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A couple of key moments here: with custom validation, we are using the method &lt;strong&gt;“validate”&lt;/strong&gt;, not &lt;strong&gt;“validates”&lt;/strong&gt;, and then we are passing it a method that we define ourselves below. We also specify our custom error, should the user not follow our &lt;em&gt;fave_destination&lt;/em&gt; rule. &lt;/p&gt;

&lt;p&gt;Speaking of errors, ideally we want our controller to tell us if, for example, our user data was saved successfully, and if not, tell us exactly why not. How would we do it with built-in validations? Below we are updating our controller action to provide is a specific response if the user was not saved successfully:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0eu5jcp8moctxy7td46a.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0eu5jcp8moctxy7td46a.PNG" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And there we have it - we just learned the best ways to ensure our data integrity using Active Record!&lt;/p&gt;

</description>
      <category>rails</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Ruby Variables</title>
      <dc:creator>Leissan </dc:creator>
      <pubDate>Mon, 03 Oct 2022 02:25:27 +0000</pubDate>
      <link>https://dev.to/leissan/ruby-variables-2pn4</link>
      <guid>https://dev.to/leissan/ruby-variables-2pn4</guid>
      <description>&lt;p&gt;In programming, a &lt;strong&gt;variable&lt;/strong&gt; is basically a container which allows us to store information, something that holds a value.&lt;/p&gt;

&lt;p&gt;Ruby has &lt;strong&gt;5 different types of variables&lt;/strong&gt;: as you might expect, there are local and global variables, there are instance and class variables, and there are constants. The way we can tell which is which is typically by using a special character at the beginning of the variable name. Let’s review them one by one.&lt;/p&gt;

&lt;h3&gt;
  
  
  Local Variables
&lt;/h3&gt;

&lt;p&gt;A local variable name always starts with a lowercase letter(a-z) or underscore (_). These variables are local to the code block in which they are declared; their scope ranges from class, module, def, or do to the corresponding end or from a block's opening brace to its close brace {}. A local variable is only accessible locally, within the block of its initialization. Local variables are not available outside that block. &lt;/p&gt;

&lt;p&gt;Local variables do not have any value (even nil) before initialization, which means you will encounter an error like the one below if you try to declare one without assigning its value:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7h5rG7eA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/40qln6k69i0sb8jmxg8f.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7h5rG7eA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/40qln6k69i0sb8jmxg8f.PNG" alt="Image description" width="800" height="199"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first assignment you make to a local variable works essentially like a declaration. When you are trying to reference an initialized local variable, Ruby interprets it as a call to a method that has no arguments (and we get the error like the one above).&lt;/p&gt;

&lt;h3&gt;
  
  
  Global Variables
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Global Variables&lt;/strong&gt; start with a dollar sign: $:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VUYC1xjo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z9tzj4s2iocjjdq16nwt.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VUYC1xjo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z9tzj4s2iocjjdq16nwt.PNG" alt="Image description" width="800" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In our code snippet above, we are declaring the global variable on top level, outside of any class. When we test this code in IRB, we can see that this variable is available (or in scope) in both classes:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7uCzELbz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ehbo8g4lra5vz05mesh.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7uCzELbz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ehbo8g4lra5vz05mesh.PNG" alt="Image description" width="800" height="222"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see the scope of the global variable is such that it can be accessed across classes, from anywhere in your program, in other words – the scope is global. When a global variable is uninitialized, it has no value by default and its use is nil.&lt;/p&gt;

&lt;h3&gt;
  
  
  Instance Variables
&lt;/h3&gt;

&lt;p&gt;An &lt;strong&gt;instance variable&lt;/strong&gt; always starts with a @ sign. It is defined within the class body and belongs to a specific instance of that class. Its value is not shared between different instances of that class but rather it is local to specific instances of an object. Instance variables are available across methods for any specified instance or object i.e. instance variables can change from object to object. There is no need to initialize the instance variables and uninitialized instance variable always contains a nil value. &lt;/p&gt;

&lt;p&gt;In the code snipper below, we created a class Toy, which has specific attributes like name and color. These attributes become our instance variables, with @ sign in front of them. As you can see, instance variables are declared inside the class.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6aTVn6OP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kznefo5pel9zzb3gga4f.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6aTVn6OP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kznefo5pel9zzb3gga4f.PNG" alt="Image description" width="800" height="201"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here we created two new instances of our Toy class: a red ball and a yellow truck. These attributes are describing not the entire class but only that specific instance (or instances) we created.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uBE4Jm_8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hjxhj8mo3xbdij9jld98.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uBE4Jm_8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hjxhj8mo3xbdij9jld98.PNG" alt="Image description" width="800" height="114"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;An instance variable belongs to the object itself (each object has its own instance variable of that particular class). One instance object can alter the values of its instance variables without modifying any other instance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Class Variables
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;class variable&lt;/strong&gt; is a variable defined in a class body that can be interacted with without an instance of such class. Class variables are shared among all instances of the class and its subclasses. This means that only one variable value exists for all objects instantiated from this class. If one object instance changes the value of the variable, that new value will essentially change for all other object instances. It may make more sense once you review the code below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TiuuZvi8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/70yr2d3c4ol8cbd1tk3z.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TiuuZvi8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/70yr2d3c4ol8cbd1tk3z.PNG" alt="Image description" width="539" height="442"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, we have the same instance variables we reviewed above (&lt;a class="mentioned-user" href="https://dev.to/name"&gt;@name&lt;/a&gt;, @color), as well as a class variable @@toy_count. The reason we are using a class variable here is because we need to keep track of data beyond just the instance level. Each instance of the toy has no idea how many other instances are there; it seems like the job is better suited for our class Toy.&lt;/p&gt;

&lt;p&gt;The key practical difference between a class and an instance variable is that class variables (@@) are shared among a class and all of its descendants (like toy_count in our example), while instance variables (@)  are not shared and each class has separate instance variables just like you would expect from different objects (like red ball and yellow truck). &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Euw-qGMA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/djda802zlyiizyxt5amq.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Euw-qGMA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/djda802zlyiizyxt5amq.PNG" alt="Image description" width="800" height="169"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Constant Variables
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;constant&lt;/strong&gt; is a type of variable which always starts with a capital letter. They can only be defined outside of methods, unless you use metaprogramming.&lt;br&gt;
As long as you create a constant outside of any class, at the top-level of your code, that constant will be available anywhere, including inside class methods, outside the class, and in child classes.&lt;br&gt;
Constants are used for values that aren’t supposed to change, but Ruby doesn’t prevent you from changing them, which could potentially be tricky for your code. This is why you wouldn’t typically use them very often in your code.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Exchanging data between React components</title>
      <dc:creator>Leissan </dc:creator>
      <pubDate>Sun, 10 Jul 2022 13:28:47 +0000</pubDate>
      <link>https://dev.to/leissan/exchanging-data-between-react-components-4b0l</link>
      <guid>https://dev.to/leissan/exchanging-data-between-react-components-4b0l</guid>
      <description>&lt;p&gt;A &lt;strong&gt;Component&lt;/strong&gt; is one of the core building blocks of React. A React component takes an optional input and returns a React element which is rendered on the screen. How the data is passed between the components will depend on their hierarchy, or Parent/ Child/ Sibling relationship.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Passing data from the Parent component to a Child Component&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The most straightforward way to pass data between components is to pass it from a parent to a child, which is be done by using &lt;strong&gt;props&lt;/strong&gt;. React allows you to pass props but only in one direction, parent to a child, and not the other way around. In the example I have below, we are passing a prop with a name of &lt;em&gt;faveSnack&lt;/em&gt; that is equal to a value of a string (in our case, of course, &lt;em&gt;“pizza”&lt;/em&gt;). Passing a prop gives us access to the information in our Child component. To access the prop in our Child component we use &lt;em&gt;props.faveSnack&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8C8pOrDP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hwkhxwj5re63v3ge3f20.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8C8pOrDP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hwkhxwj5re63v3ge3f20.PNG" width="527" height="412"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We could also just use our prop faveSnack directly, through something that’s called &lt;strong&gt;destructuring props&lt;/strong&gt;. This is what it would look like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AgGRIMu5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jvfr5bv09ohtpympucrr.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AgGRIMu5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jvfr5bv09ohtpympucrr.PNG" alt="Image description" width="561" height="435"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Passing data from a Child component to a Parent component.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here is where things are starting to get tricky, because  - as you now know – we cannot pass props from a child to a parent. What we can do however is use &lt;strong&gt;callback functions&lt;/strong&gt;. When we use a callback function in a Child component it can then make changes to a Parent component.&lt;/p&gt;

&lt;p&gt;Let’s review the steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; In the parent component, create a callback function. This callback function will retrieve the data from the child component.&lt;/li&gt;
&lt;li&gt; Pass the callback function to the child as a props from the parent component.&lt;/li&gt;
&lt;li&gt; The child component calls the parent callback function using props and passes the data to the parent component.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the example below, we are using the callback function to handle the &lt;em&gt;onChange event&lt;/em&gt; in the child component and pass the value from the input element as an argument to the callback function passed down as a prop, which is called &lt;em&gt;snackHandler&lt;/em&gt; here. The function &lt;em&gt;handleSnackChange&lt;/em&gt; takes an argument – an event, and passes the current value to the snack state variable. The event handler, while it is defined in the Parent component (or owned by it), is passed to the Child component as a prop and then called in that same Child component (or invoked by it). &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zbLj1-cS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u88tf27gk88htsvb1zxy.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zbLj1-cS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u88tf27gk88htsvb1zxy.PNG" alt="Image description" width="800" height="484"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Passing data between 2 Child components, or siblings.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In order to pass data between siblings, there are several methods we can choose from:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Combination of the above two methods (callback and use of props).&lt;/li&gt;
&lt;li&gt;Using Redux.&lt;/li&gt;
&lt;li&gt;ContextAPI&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For this post, I will focus on the first method in the spirit of establishing the communication channel between components using just React.&lt;/p&gt;

&lt;p&gt;There is no direct way to pass the data between two (or more) children components; we need to use the Parent as a way to connect the siblings. The easiest way to think about it would mean combining the first two ways of passing data between the components that we just went over above. &lt;/p&gt;

&lt;p&gt;First, we would need to define a &lt;strong&gt;callback function&lt;/strong&gt; in a Parent component (which will own the callback function) and then send it to Child 1 as a &lt;strong&gt;prop&lt;/strong&gt;. We are setting a state variable &lt;em&gt;“snack”&lt;/em&gt; and updating its value using the callback function from Child 1, the way we did it above in the example of passing data from a Child to a Parent. The &lt;em&gt;onChange&lt;/em&gt; event in Child1 component is being handled by the callback function &lt;em&gt;handleSnackChange&lt;/em&gt; which is passed to Child1 as &lt;em&gt;snackHandler&lt;/em&gt; prop from a Parent component. The value from Child1 input element  is passed as an argument to the callback function &lt;em&gt;handleSnackChange&lt;/em&gt; which in turn passes the current value to the snack state variable. &lt;/p&gt;

&lt;p&gt;So far, the steps have been identical to the ones described in passing data from Child to Parent, since, as we established already, the parent must act as the intermediary between the siblings. Now that we passed the data from Child1 to the parent (as an argument in a callback function), we are setting it in a state in Parent component, then passing it as a prop to Child2:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u02ksLSM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vi8bojm1dt66d35tk0ss.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u02ksLSM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vi8bojm1dt66d35tk0ss.PNG" alt="Image description" width="643" height="560"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To sum up, we can pass data from a Parent to a Child component using props, from a Child to a Parent using a callback function, and between the siblings using a combination of both.&lt;/p&gt;

&lt;p&gt;Thank you for reading!&lt;/p&gt;

</description>
      <category>react</category>
      <category>beginners</category>
    </item>
    <item>
      <title>JavaScript Variables</title>
      <dc:creator>Leissan </dc:creator>
      <pubDate>Fri, 15 Apr 2022 03:39:09 +0000</pubDate>
      <link>https://dev.to/leissan/javascript-variables-37je</link>
      <guid>https://dev.to/leissan/javascript-variables-37je</guid>
      <description>&lt;p&gt;First of all, let's define what is a &lt;strong&gt;variable&lt;/strong&gt;. Simply put, a variable is something that holds a value. It has an identifier (or a name) which can contain letters, digits, and special symbols. In order for us to "declare" a variable we can use three methods: let, var, and const.&lt;/p&gt;

&lt;p&gt;As a general rule, if you do not want the value of your variable to change throughout the entirety of your code, declare it using &lt;strong&gt;const&lt;/strong&gt; (the value will remain constant, get it?). This will ensure that it cannot be redeclared and cannot be reassigned. Let's see that in action:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const snack = "ice-cream"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here we declared our variable (snack) and assigned a value to it (ice-cream). If we want to retrieve the value of our variable, we can simple run &lt;em&gt;snack&lt;/em&gt; and get &lt;em&gt;ice-cream&lt;/em&gt; in return:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jovmdFPg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hnslh9s4ayajq7kyncyn.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jovmdFPg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hnslh9s4ayajq7kyncyn.PNG" alt="Image description" width="454" height="104"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What happens if we try to re-assign the value? Let's see:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WhNKjQ7j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w0cb9ud0hg4rdhwt9hlg.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WhNKjQ7j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w0cb9ud0hg4rdhwt9hlg.PNG" alt="const1" width="492" height="155"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hmmmm it doesn't like that. Perhaps we can just re-declare the value?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qgW27bXK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3n2kw70o8bn2uje5tdgj.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qgW27bXK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3n2kw70o8bn2uje5tdgj.PNG" alt="Image description" width="586" height="146"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nope, that does not work either! &lt;/p&gt;

&lt;p&gt;What if we would like a bit more flexibility here, and want to be able to re-assign the value of a variable? Here we would use the variable &lt;strong&gt;let&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zUgGchBN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uk932sv7zdgibhaemh00.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zUgGchBN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uk932sv7zdgibhaemh00.PNG" alt="let" width="478" height="198"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Mind you, we still will not be able to re-declare the value of &lt;strong&gt;let&lt;/strong&gt;, but we can re-assign it. In the same situation, &lt;strong&gt;const&lt;/strong&gt; is throwing us an error.&lt;/p&gt;

&lt;p&gt;And most flexible of all, &lt;strong&gt;var&lt;/strong&gt;, can be both re-declared and re-assigned it's value:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--z-os58oe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uat12w9hhaz2ecigu5p0.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z-os58oe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uat12w9hhaz2ecigu5p0.PNG" alt="Image description" width="408" height="202"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, to sum it up, var variables can be re-assigned value and re-declared; let variables can be re-assigned value but not re-declared; const variables can neither be re-assigned value nor re-declared.&lt;/p&gt;

&lt;p&gt;But these are not the only differences; they also differ in &lt;strong&gt;scope&lt;/strong&gt;, or essentially in their availability for use in various parts of code. Here we will cover two types of scope: global and local.&lt;/p&gt;

&lt;p&gt;If a variable is declared outside of any function it is a &lt;strong&gt;global&lt;/strong&gt; variable. Global variables can be accessed from within any function:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9lOn_E_t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/24zhct0ztmlmblw3rdge.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9lOn_E_t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/24zhct0ztmlmblw3rdge.PNG" alt="global scope" width="371" height="161"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Variables declared inside any function are called &lt;strong&gt;local&lt;/strong&gt; variables. Local variables cannot be accessed outside the function:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dzLWvVfZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/645rd3inefz6joem5hu8.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dzLWvVfZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/645rd3inefz6joem5hu8.PNG" alt="local scope" width="437" height="139"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;An important thing to note is that in JavaScript, a variable can also be used &lt;em&gt;without declaring it&lt;/em&gt;, meaning we will not use var, let, or const to declare it. If a variable is used without declaring it, that variable automatically becomes a global variable:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QWcCYZgp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mk622l1axvy71doa1vk2.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QWcCYZgp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mk622l1axvy71doa1vk2.PNG" alt="variable not declared" width="402" height="158"&gt;&lt;/a&gt;&lt;br&gt;
We should also mention something that’s called a &lt;strong&gt;block&lt;/strong&gt; scope. A block is, generally speaking, anything within curly brackets; it could be for or while loops, if statement, etc. Block scoping means declaring a variable inside those curly brackets. It is within the concept of a block scope that we can see different behaviors of our three variables. &lt;/p&gt;

&lt;p&gt;When it comes to a var variable,  it is globally scoped if we declare it outside of the function, and locally (or functionally) scoped if we declare it within the function. It is not block scoped! This means if we declare a variable using var inside a block of code, we can just as easily access it outside of that block of code, on a function level:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NmPyqQzS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6m9h0qfmd6u4n5a44r1s.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NmPyqQzS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6m9h0qfmd6u4n5a44r1s.PNG" alt="Image description" width="428" height="242"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see, we have no issue printing out the value of a variable “snack” (which was defined inside a block of code) both within the block and outside of it. That, along with the fact that we can both re-assign and re-declare it’s value, can potentially create complications and errors in our code, which is why const and let are typically preferred over var.&lt;/p&gt;

&lt;p&gt;You see, unlike var, both const and let actually respect the block scope; if we declare a variable using these two inside a block of code, we will not be able to access it from the outside of the curly brackets, not on a function level, and not on a global level.  This can open up a lot more possibilities for our code! Let’s see how const behaves in the very same situation we just saw above:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HPjLCcwv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2eb8cpqitiqrderfafvj.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HPjLCcwv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2eb8cpqitiqrderfafvj.PNG" alt="Image description" width="436" height="258"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see, only the console.log inside the block of code worked. We can observe the same behavior with let:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FC4hH12m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ohpkbw8jwzbprc7zx4f1.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FC4hH12m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ohpkbw8jwzbprc7zx4f1.PNG" alt="Image description" width="470" height="255"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To sum up, the main differences when it comes to scope are: let and const variables are block scoped, var are NOT (only globally or functionally scoped). These differences, along with the differences in their ability to be re-declared and re-assigned, open up very different possibilities with each of these variables when we code.&lt;/p&gt;

&lt;p&gt;Thank you for reading!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uRU0oV9r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://c.tenor.com/JiNfNwrkjtEAAAAC/cat-funny.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uRU0oV9r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://c.tenor.com/JiNfNwrkjtEAAAAC/cat-funny.gif" width="498" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

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