<?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: Ismail Labbi</title>
    <description>The latest articles on DEV Community by Ismail Labbi (@ismailabbi).</description>
    <link>https://dev.to/ismailabbi</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%2F720733%2F71e01935-aff7-4a79-9d5f-883d6e123564.jpeg</url>
      <title>DEV Community: Ismail Labbi</title>
      <link>https://dev.to/ismailabbi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ismailabbi"/>
    <language>en</language>
    <item>
      <title>The ABCs of Angular : Dependency Injection Provider &amp; Provide Part 2</title>
      <dc:creator>Ismail Labbi</dc:creator>
      <pubDate>Thu, 08 Jun 2023 21:22:20 +0000</pubDate>
      <link>https://dev.to/ismailabbi/the-abcs-of-angular-dependency-injection-provider-provide-part-2-1gke</link>
      <guid>https://dev.to/ismailabbi/the-abcs-of-angular-dependency-injection-provider-provide-part-2-1gke</guid>
      <description>&lt;p&gt;In the previous &lt;a href="https://dev.to/ismailabbi/the-abcs-of-angular-dependency-injection-part-1-2ji0"&gt;article&lt;/a&gt;, we introduced the useClass property within the providers array to define how the Angular Dependency Injection system instantiates a class. In this article, we will delve deeper into this syntax and explore providers in Angular.&lt;/p&gt;

&lt;p&gt;Before we proceed, let's refresh our memory 😁 .&lt;/p&gt;

&lt;p&gt;In Angular, providers are an array of instructions, where each provider is an instruction or recipe that describes how an object for a particular class, string, token, etc., is created.&lt;/p&gt;

&lt;p&gt;Now, let's focus on a specific object in the providers array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{ provide: LoggerService, useClass: LoggerService }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This Provider object contains two properties: provide and useClass.&lt;/p&gt;

&lt;p&gt;The provide property represents the identifier of the provider, which can be either a string or an instance of InjectionToken. In our example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Contructor(public loggerService:LoggerService)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we inject an instance of LoggerService into a component's constructor using LoggerService as the token 🥴🥴. &lt;/p&gt;

&lt;p&gt;If this isn't clear, don't worry; examples will help you understand it better  😉.&lt;/p&gt;

&lt;p&gt;Consider the following modified provider syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;providers: [
  { provide: LoggerService, useClass: BetterProductService }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, when Angular encounters the need to inject LoggerService in a constructor, it will search the providers and find LoggerService. However, instead of injecting LoggerService, it will inject BetterProductService. In other words, the provide: LoggerService is merely a token used to identify what we want to inject.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For your Information :&lt;/em&gt; &lt;br&gt;
Angular doesn't complain if the token is used multiple times. In the following example, the token LoggerService is used twice, but the last registration (BetterProductService) takes precedence.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;providers: [
  { provide: LoggerService, useClass: LoggerService },
  { provide: LoggerService, useClass: BetterProductService }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;You should also know that the token can also be a string ! *&lt;/em&gt;&lt;br&gt;
For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;providers: [{ provide: 'LoggerService', useClass: LoggerService }]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, 'LoggerService' serves as a string token. To inject LoggerService, we can use the @Inject decorator as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export class AppComponent {
  constructor(@Inject('LoggerService') private loggerService: LoggerService) {}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, using string tokens can introduce naming collisions if multiple parts of your application use the same string for different purposes. This can lead to conflicts and make your code harder to understand.&lt;/p&gt;

&lt;p&gt;To address this, Angular provides the InjectionToken&lt;/p&gt;

&lt;h2&gt;
  
  
  What is an Injection Token?
&lt;/h2&gt;

&lt;p&gt;An Injection Token is similar to a string token, but instead of using a hardcoded string, we create the Injection Token by instantiating the InjectionToken class. This ensures that the tokens are always unique.&lt;/p&gt;

&lt;p&gt;To create an Injection Token, import InjectionToken from @angular/core:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { InjectionToken } from '@angular/core';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, create a new instance of InjectionToken with a unique name, such as LoggerServiceToken:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const LoggerServiceToken = new InjectionToken&amp;lt;string&amp;gt;('LoggerService');

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we specify the optional type parameter  and the token description, which helps clarify the token's purpose.&lt;/p&gt;

&lt;p&gt;Register the Injection Token in the providers array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;providers: [
  { provide: LoggerServiceToken, useClass: LoggerService },
  // Other providers...
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you can inject the LoggerService using the Injection Token in your component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export class AppComponent {
  constructor(@Inject(LoggerServiceToken) public loggerService: LoggerService) {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the next article, we will explore additional properties of the provider object in Angular. Apart from provide, there are other properties that can be used to configure the dependency injection behavior.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>typescript</category>
      <category>javascript</category>
      <category>frontend</category>
    </item>
    <item>
      <title>The ABCs of Angular : Dependency Injection Part 1</title>
      <dc:creator>Ismail Labbi</dc:creator>
      <pubDate>Tue, 23 May 2023 22:01:54 +0000</pubDate>
      <link>https://dev.to/ismailabbi/the-abcs-of-angular-dependency-injection-part-1-2ji0</link>
      <guid>https://dev.to/ismailabbi/the-abcs-of-angular-dependency-injection-part-1-2ji0</guid>
      <description>&lt;h2&gt;
  
  
  What is Dependency Injection?
&lt;/h2&gt;

&lt;p&gt;Let’s start with an example to better understand 😃.&lt;/p&gt;

&lt;p&gt;I have a LoggerService class that implements a log method. This method helps us display messages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export class LoggerService {
  log(message: string) {
    console.log(`Logger Service: ${message}`);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, suppose I have a UserService that needs the LoggerService to display some messages. We could instantiate the LoggerService directly in UserService like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export class UserService {
  private loggerService: LoggerService;

  constructor() {
    this.loggerService = new LoggerService();
  }

  getUser() {
    // Fetch user logic...
    this.loggerService.log('User fetched successfully!');
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While this approach works, it is generally less flexible and more difficult to maintain. For example, if you ever wanted to replace LoggerService with a different implementation, you would need to manually change all the places in your code where LoggerService is instantiated. Moreover, it's your responsibility to manage the entire lifecycle of that dependency, including its destruction. Hence, we need a mechanism that instances dependencies for us and manages the lifecycle of those dependencies&lt;/p&gt;

&lt;p&gt;💥💥&lt;strong&gt;And the solution is Dependency Injection (DI):&lt;/strong&gt;💥💥&lt;/p&gt;

&lt;p&gt;Dependency Injection is a design pattern where a class receives its dependencies from an external source rather than creating them itself. These dependencies are often instances of other classes.&lt;/p&gt;

&lt;p&gt;Angular implements this pattern for us. The new implementation will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export class UserService {
  constructor(private loggerService: LoggerService) { }

  getUser() {
    // Fetch user logic...
    this.loggerService.log('User fetched successfully!');
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There's no need to instantiate the dependency (LoggerService) manually. Angular will do this for us by using the Dependency Injection pattern.&lt;/p&gt;

&lt;p&gt;However, if you write this code in your project, unfortunately, you might encounter this type of error: R3InjectorError(AppModule)[LoggerService -&amp;gt; LoggerService -&amp;gt; LoggerService]: NullInjectorError: No provider for LoggerService! 😡😡😡&lt;/p&gt;

&lt;p&gt;Don't fear, the solution is simple 😁 😁. The error message "no provider" simply means that the Angular Dependency Injection system can't instantiate a given dependency because it doesn't know how to create it.&lt;/p&gt;

&lt;p&gt;In Angular, we define how to create our dependencies using the providers array in the module. By adding our services to this array, we tell Angular when and how to create them. This way, the services are set up and ready for use throughout our application with Angular's Dependency Injection system:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule
  ],
  providers: [{
    provide: LoggerService,
    useClass: LoggerService
  }],
  bootstrap: [AppComponent]
})

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the providers array, we add a new object. To understand this object, we need to ask two questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Which class do we want to instantiate and return? This is the value of the useClass property.&lt;/li&gt;
&lt;li&gt;When to return this instantiated class? Each time we call LoggerService as a dependency, which is defined by the provide property.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And Angular simplifies this for us; we don't need to write all the mentioned code 😎. We can simply write providers: [LoggerService] and Angular takes care of the rest. And voilà, our service is ready to be injected and used . &lt;/p&gt;

&lt;p&gt;Let's stop here so we don't overwhelm you. In our next session, we'll dive deeper into more details and uncover the miracles of Dependency Injection in Angular&lt;/p&gt;

</description>
      <category>angular</category>
      <category>typescript</category>
      <category>javascript</category>
      <category>frontend</category>
    </item>
    <item>
      <title>The ABCs of JavaScript : Closures</title>
      <dc:creator>Ismail Labbi</dc:creator>
      <pubDate>Mon, 20 Mar 2023 23:42:01 +0000</pubDate>
      <link>https://dev.to/ismailabbi/the-abcs-of-javascrip-closures-10l8</link>
      <guid>https://dev.to/ismailabbi/the-abcs-of-javascrip-closures-10l8</guid>
      <description>&lt;p&gt;Hello and welcome to "The ABCs of JavaScript"! In today's lesson, we'll be delving into the fascinating topic of &lt;em&gt;&lt;strong&gt;closures&lt;/strong&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;In JavaScript, Closures are an important and advanced feature in JavaScript that provide functions with access to variables scope and parameters of their outer function, even when the function is executed outside that outer function.&lt;/p&gt;

&lt;p&gt;If you're unclear about closures defintion, don't worry, we'll break it down step by step. &lt;/p&gt;

&lt;p&gt;First, let's clarify what an_ outer function and inner function_ means.&lt;br&gt;
In JavaScript, functions can be defined inside other functions, like in the example below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function outerFunction() {
  console.log("This is an outer function.");

  function innerFunction() {
    console.log("This is an inner function.");
  }

  innerFunction();
}

outerFunction();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the function that encloses the nested function is called &lt;strong&gt;outerFunction&lt;/strong&gt;, and the nested function is called &lt;strong&gt;innerFunction&lt;/strong&gt; very simple 😊😊.&lt;br&gt;
 You might ask why we need to declare functions like this instead of declaring them separately. While that is not our subject, let me give you some pointers to explain why this is useful in JavaScript  😇  😇:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Encapsulation: Defining a function inside another function allows you to encapsulate that function and its functionality within a specific scope.&lt;/li&gt;
&lt;li&gt;Information Hiding: If you have a function that relies on some variables or other functions that are not relevant to the rest of your program.&lt;/li&gt;
&lt;li&gt;Reusability&lt;/li&gt;
&lt;li&gt;Performance&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's return to our concept. As we saw earlier, the nested function is called the inner function. However an inner function can create a &lt;strong&gt;_closure _&lt;/strong&gt;when it references variables from its outer scope! That's right, we've arrived at the heart of the matter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function outerFunction() {
  let increment = 0;
  console.log("This is an outer function.");

  function innerFunction() {
    increment = increment + 1;
    console.log(increment);
    console.log("This is an inner function.");
  }

  innerFunction();
}

outerFunction()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we execute this code, we will see the value 1 in our terminal because the inner function (or closure) has access to the variable of its outer function as we explained earlier in the definition.&lt;/p&gt;

&lt;p&gt;But there's something even more powerful about closures 🚀 🚀 . Let's modify our code again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
function outerFunction() {
  let increment = 0;
  console.log("This is an outer function.");

  return function innerFunction() {
    increment = increment + 1;
    console.log(increment);
    console.log("This is an inner function.");
  }
}

let incrementMethod = outerFunction();
incrementMethod(); //1;
incrementMethod();//2;
incrementMethod();//3;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Did you see this beautiful magic 😍 😍? Even though the outer function has finished executing, the inner function still has access to the increment variable in its state. This demonstrates the power of closures - they can still access the variables of their outer function even after it has finished executing.&lt;/p&gt;

&lt;p&gt;To remember this concept in JavaScript, here's a useful trick: always imagine that each function has a backpack. Before any execution of any function, the backpack is filled with all information preceding the declaration of the function. When the function is executed, it has its own backpack that it can access.&lt;/p&gt;

&lt;p&gt;In our example, the inner function's backpack is filled with the "increment" variable, and it will always be in its backpack even if the outer function has finished execution.&lt;/p&gt;

&lt;p&gt;I hope this article helped you to better understand the concept of closures. See you in another article!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The ABCs of JavaScript: Autoboxing in javascript</title>
      <dc:creator>Ismail Labbi</dc:creator>
      <pubDate>Mon, 27 Feb 2023 23:41:00 +0000</pubDate>
      <link>https://dev.to/ismailabbi/the-abcs-of-javascript-autoboxing-in-javascript-5fh4</link>
      <guid>https://dev.to/ismailabbi/the-abcs-of-javascript-autoboxing-in-javascript-5fh4</guid>
      <description>&lt;p&gt;In our previous &lt;a href="https://dev.to/ismailabbi/the-abcs-of-javascript-primitive-and-object-types-3982"&gt;article &lt;/a&gt;, we discussed that JavaScript has not only objects but also primitive types. We also mentioned that primitive types do not have properties or methods since they are not objects.&lt;/p&gt;

&lt;p&gt;However, let's test this point to confirm whether it is true or not. Try running this code in your editor:&lt;br&gt;
&lt;code&gt;const name = "john";&lt;br&gt;
console.log(name.length);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The output will be 4, which refers to the number of characters in the string. But wait, &lt;strong&gt;didn't we just say that primitive data types don't have properties?&lt;/strong&gt; 😠 😠 😠 😠&lt;/p&gt;

&lt;h2&gt;
  
  
  Autoboxing
&lt;/h2&gt;

&lt;p&gt;Don't worry, there is an explanation for this 😊 😊. Although primitive values don't have properties or methods, JavaScript uses the concept of &lt;strong&gt;&lt;em&gt;autoboxing&lt;/em&gt;&lt;/strong&gt; to create a temporary object wrapper around the value when we use a property or method on a primitive value.&lt;/p&gt;

&lt;p&gt;So, when we use the .length property on the string primitive name, JavaScript automatically creates a temporary String object wrapper around the value "john", which allows us to access the .length property.&lt;/p&gt;

&lt;p&gt;We should note that this object is a built-in object in JavaScript, and there are many predefined objects such as String, Boolean, Date, and Math. JavaScript detects the type of primitive data that we create and automatically creates an object that corresponds to that data type. For example, since we created a string primitive in our example, the object created by JavaScript is a String object.&lt;/p&gt;

&lt;h2&gt;
  
  
  manual boxing
&lt;/h2&gt;

&lt;p&gt;We can also perform manual boxing ourselves. Here's an example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let firstName = String("naima");&lt;br&gt;
console.log(firstName.length);&lt;br&gt;
console.log(name.valueOf()); // "john"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In this example, we create an object directly without using autoboxing, and we can retrieve our primitive value using the valueOf() method.&lt;/p&gt;

&lt;p&gt;I hope this article helps to clear up the confusion that exists around primitive types in JavaScript&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The ABCs of JavaScript: Primitive and Object types</title>
      <dc:creator>Ismail Labbi</dc:creator>
      <pubDate>Mon, 20 Feb 2023 23:36:54 +0000</pubDate>
      <link>https://dev.to/ismailabbi/the-abcs-of-javascript-primitive-and-object-types-3982</link>
      <guid>https://dev.to/ismailabbi/the-abcs-of-javascript-primitive-and-object-types-3982</guid>
      <description>&lt;p&gt;In JavaScript, there is a common saying that "&lt;strong&gt;everything is an object&lt;/strong&gt;" while objects are a fundamental concept in JavaScript, there are other data types that are not objects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Primitive Data
&lt;/h2&gt;

&lt;p&gt;primitive data types in JavaScript, including strings, numbers, booleans, bigints, symbols, and undefined. While these data types are not objects,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log( typeof "test")//string
console.log( typeof 3)//number
console.log(typeof true)//boolean
console.log( typeof null)//object
console.log( typeof 42n)//bigint
console.log(typeof Symbol()) //symbol 
console.log( typeof undefined)//undefined

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't worry about the null type, even though it is displayed as an object, it is actually a primitive type. We will return to this topic in a future article.&lt;/p&gt;

&lt;h2&gt;
  
  
  Primtive vs Object
&lt;/h2&gt;

&lt;p&gt;Understanding the difference between objects and primitive values in JavaScript is crucial. There are two main differences to note:&lt;/p&gt;

&lt;p&gt;Primitive data does not have properties or methods, which is to be expected since they are not objects. This is a straightforward concept.&lt;/p&gt;

&lt;p&gt;Objects are mutable, while primitives are immutable. This means that once a primitive value is created, its value cannot be changed. On the other hand, objects can be changed after they are created, and modifications to their properties or values will be reflected in the original object.&lt;/p&gt;

&lt;h2&gt;
  
  
  But what does 'mutable' and 'immutable' mean?
&lt;/h2&gt;

&lt;p&gt;'Immutable' means that values cannot be modified after creation.&lt;/p&gt;

&lt;p&gt;Let's take an example to better understand this approach.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let obj = {
    a:1
}

function incrementByOne(arg){
    arg.a = arg.a + 1
    console.log(arg.a) //2
 }

 incrementByOne (obj)//2

 console.log(obj.a)//2

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have an object called 'obj' that has a property named 'a' with a stored value of 1. We pass our object to the 'incrementByOne' function, which increments our property value by one. The first console log displays 2, and when we display our object outside the function, the console log displays the same value of 2. This demonstrates that the object's value was changed after creation from 1 to 2,  We can easily modify its state.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Is it still not clear? *&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;the concept may become clearer with the second example, which involves 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 number = 3

function incrementByOne (arg){
   arg = arg + 1
   console.log(arg)//4
}

incrementByOne (number)// 4

console.log(number)//3

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We're applying the same function, but this time we're using a number instead of an object. It's clear that the first console log displays 4, but outside the function, the number remains the same as its original value of 3. This is because primitive values pass a copy of themselves to the function, and because they're immutable, their values can't be changed after creation.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Maybe you will say&lt;/strong&gt;&lt;/em&gt; : I can change its value after creation by assigning a new value as &lt;code&gt;Let number = 3 &lt;br&gt;
  number =4&lt;br&gt;
&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;Unfortunately, no. You are not changing its value or state of creation, but rather creating a new value for our data.&lt;/p&gt;

&lt;p&gt;We should really understand that when we assign a value to our variable, we create space in memory for this data. We create a container where we store our value 3. But when you assign a new value to your primitive value, you will create a new container and store the number 4 for our variable. In contrast, if you modify or assign our object, you will just modify the first container that was created.&lt;/p&gt;

&lt;p&gt;I hope that I have helped to explain the difference between immutable and mutable, and that you now understand the difference between objects and primitive values.&lt;/p&gt;

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