3.1 updating of reference and primitive type

Okay so what we’re going to learn today are things that we really need to keep in mind the first feature or the concept of JavaScript that I’m talking about the fact that you have reference titles and primitive types if I create a number like this-this is a primitive type it means that if I create a second number Num two and the me is equal to this number it will create a real copy of number so number two of course now if I put console log and I go on my test page you can see that there is marked 1 of the coup il a copié de valeur dans numéro deux maintenant les nombre les chaînes les booléens These are the primitive types each time you reassign or you Store a variable in another variable

it will copy the value of the objects the tables are reference types but letI show you what I mean I create my personal object that just has a name here and I now create a second person is a person signed up as worth here so now I put console. Log with second person in and if I go in the console and it will display the same value as the first person but will not have copied it instead no objects is stored in memory and in constant person we store a pointer to that place in memory and if we then assign a second person this pointer will be copied we can see that this is the case only if we changed person with that-there you expect to print again here a person with the name of Matthew as we had copied it store in a second person and then edit.

now if I empty and go to the console you will see the name here you see the max name the name of the second person also changed when it just copied the pointer is the green dot the same object in memory as the person so if we change the name of a no one we automatically change it per second person keep in mind and it’s the same for tables if you copy a table in quotation marks like that and then you change a table element everything will change in the table said copy it will become important in reac because it can lead to unexpected behaviors actually if you cut objects from tables of this type you can then manipulate an object a place of the application and manipulate accidentally message of the use of the same object another place of the application we will therefore learn techniques to copy this in an immutable way which means that we will copy this by actually copying the object and not just a pointer because we can use this operator

Now we just need to create the person object here and spread the properties of those people that will extract the properties and values of the properties of the object and add it to that object I show you remember the... In the last video of the hit now if we go here It puts us name Matthew even if we changed name by Max here it will put Matthew back because now we have created a real copy it is just important to realize and keep in mind that the objects I the tables are reference types if I wanted to reassign pointer in its value therefore if you want to perform this operation in a real way you will have to create a new object is simply copy the properties and not the entire object that is some important thing to keep in mind