I often find it challenging to begin my journal entries. I sometimes wonder, “What do I have to talk about?” and my mind goes blank. A blank page can be quite intimidating. This morning, I made a cup of coffee right after waking up at 5:15 am, a routine I follow every day except on weekends. After Tommy left for work, Kel and I went to pick up the mail and then headed to Walmart. She wanted bagels, which turned out to be ok since she made me breakfast. Now, I’m uncertain about what to do for lunch since I’ve already eaten. Recently, I’ve been skipping breakfast and jumping straight to lunch, but I’m not sure if I want to eat lunch today. Perhaps I’ll opt for a late lunch and keep dinner light. Tommy has band practice tonight, so we’ll probably be making our own dinners. After breakfast, I got ready for the day, made myself another cup of coffee, and that brings us to now. Kel has just left for the day; she’s on her way to the city to see Chris.
I can share what I’ve learned about cloning in JavaScript, although it may not be the most exciting topic. Perhaps I will save that discussion for the end of this entry.
It’s later in the day now, and after hours of coding, I believe it’s time for a break. I haven’t had lunch yet; I wasn’t feeling hungry earlier. Still, I should grab something to eat—perhaps just a light snack.
So, I made myself a sandwich. We’ve experienced a few power outages today, likely due to the strong winds outside causing some disruptions.
It’s now 4 PM. The kids have pooled their money together to order a pizza, but I’ll probably only have one slice. I’m not too hungry, especially since we just had pizza last Saturday.
As I mentioned, I’ll discuss cloning in JavaScript. It appears straightforward at first glance, but it becomes more complex the deeper you dive into it. Cloning simply means creating a copy of something. In JavaScript, cloning primitive values (like numbers or strings) is quite simple:
let a = 5; let b = a; // b is a copy of a
But when you deal with objects or arrays, it’s a little more complex because JavaScript handles them by reference, not by value.
Shallow Clone vs Deep Clone
🔹 Shallow Clone
Copies only the first level of an object or array. The nested objects still point to the original memory location.
let original = { name: "Alex", info: { age: 20 } }; let shallow = { ...original }; shallow.info.age = 99; console.log(original.info.age); // 99 — changed!
The … spread operator only makes a surface-level copy.
🔸 Deep Clone
Copies everything, including nested objects. So changes to the copy don’t affect the original.
let original = { name: "Alex", info: { age: 20 } }; let deep = JSON.parse(JSON.stringify(original)); deep.info.age = 99; console.log(original.info.age); // 20 — original is untouched
But this JSON method has limitations:
- Doesn’t work well with functions
- Skips undefined, Date, Map, Set, and circular references
For this function, we don’t want to use JSON or structuredClone().
Here is an example I found of deep clone:
function deepClone(obj) { if (obj === null || typeof obj !== 'object') return obj; if (Array.isArray(obj)) { return obj.map(deepClone); } const cloned = {}; for (let key in obj) { cloned[key] = deepClone(obj[key]); } return cloned; }
This version does not utilize the ‘hasOwnProperty’ method, which means it also copies inherited properties from the prototype chain. The `hasOwnProperty()` method of Object instances returns a boolean value that indicates whether the object has the specified property as its own (as opposed to inheriting it). In most cases, this behavior is acceptable; however, if you’re dealing with objects that inherit from other objects—something not commonly encountered in beginner work—it may result in the inclusion of unwanted properties.
I find this topic somewhat confusing. While I have an understanding, it still feels incomplete. If that makes sense. I’m considering going back to review some basic JavaScript to see if I can tackle the work with minimal assistance—essentially a refresher. I don’t know. I’m just struggling a bit with the concept of cloning in JavaScript. But I know I can do this.





