Deep and Shallow Copy in JavaScript
JavaScript variables hold different types of data: primitives (Undefined, Null, Boolean, Number, String) and objects (reference types). Primitive values are stored directly in memory, while objects are stored as references.
Primitive vs Reference Types
Primitive values are immutable. When copied, a new independent value is created:
let a = 1;
l ...
Posted on Fri, 14 Aug 2026 16:32:00 +0000 by scopley
Understanding Reference Pitfalls in JavaScript Array Assignments
The Reference Assignment Problem
Consider a scenaroi where a source array is assigned to a temporary variable for filtering. A common mistake is assuming that the temporary variable is an independent copy.
function filterData() {
// 'masterRecords' acts as the source of truth
let masterRecords = this.masterRecords;
// ERROR: ' ...
Posted on Thu, 23 Jul 2026 16:45:20 +0000 by advancedfuture
Prototype Pattern Implementation in Java
Vector Prototype Implementation
This implementation demonstrates mathematical vector encapsulation in Java with dynamic memory allocation for variable-length vectors. It showcases both shallow and deep cloning techniques for copying vector objects.
Shallow Cloning Approach
In shalow cloning, only the object itself is duplicated, while referance ...
Posted on Tue, 21 Jul 2026 16:21:05 +0000 by yarub
Object Cloning in Java: Shallow, Deep, and Serialization Strategies
Primitive assignments in Java duplicate the actual value:
int count = 10;
int tally = count;
This behavior applies to all eight primitive types. Object variables, however, store memory addresses rather than the objects themselves. Direct assignment therefore creates an alias, not an independent entity:
class Employee {
private int badgeId; ...
Posted on Fri, 05 Jun 2026 18:12:29 +0000 by hand
Understanding Shallow and Deep Copying of Objects in JavaScript
// Assigning a value from a to b
let a = 12;
let b = a;
This method works for primitive types. What happens if a is an object? Let's examine what occurs in memory:
Declaring a = 12 allocates a space in the stack. When a is assigned to b, another space is created in the stack, and b holds the same value as a.
If a is an object, what happens in ...
Posted on Sat, 30 May 2026 21:40:20 +0000 by RootKit
Building a Custom String Class in C++
A custom string class typically wraps a dynamically alocated character array along with size and capacity tracking. The following implementation lives inside a dedicated namespace to avoid collisions with the standard library.
namespace custom
{
class string
{
private:
char* _data;
size_t _len;
size_t _cap;
...
Posted on Fri, 08 May 2026 01:30:05 +0000 by BRUUUCE