All About - Serialization and Deserialization
First, understand the concept of serialization and deserialization. Now, assume you are sending data from one computer to another. Do you think it is simply transferred? No, first, we convert the data into a format suitable for transmission or understandable by the computer (binary). This process is called serialization. Then, after the data reaches its destination, it is converted back to its original form. This process is called deserialization.
Importance of Serialization And Deserialization in javascript objects
First of all, why do we need serialization and deserialization in JavaScript? This is mainly used for objects (as we have studied so far). A simple variable can be copied to another variable, but when we try to copy an object, it actually transfers the address (or reference) of the object. If we make changes to the copied variable, the original object also gets affected.
To create a true copy of an object in another variable, we use serialization and deserialization
Here are the steps to copy an object using serialization and deserialization, along with a diagram explanation:
Convert the object into a string (serialization).
Copy that string into another variable.
Convert the string back into an object (deserialization).