The function checks if the object is null or not an object, in which case it simply returns the value, as primitive values and null do not need further processing.
Array Handling:
If the object is an array, the function creates a new array and recursively clones each element. To handle recursive structures, a Map is used to track previously seen objects.
Object Handling:
If the object is not an array but an object, a new object is created and each key-value pair is recursively cloned. The Map is again used to track seen objects, avoiding infinite loops in cases of recursive references.
Recursive Reference Handling:
Before deep cloning, the function checks if the object has already been seen (using the Map), and if so, returns the already cloned reference, preventing infinite loops.