Memory Management and Execution on Windows — JavaScript (Node.js)

Last updated: December 13, 2025
Author: Paul Namalomba
- SESKA Computational Engineer
- Software Developer
- PhD Candidate (Civil Engineering Spec. Computational and Applied Mechanics)

Contact: kabwenzenamalomba@gmail.com
Website: paulnamalomba.github.io

Language: JavaScript Runtime: Node.js License: MIT

Overview

This guide explains how JavaScript handles memory and execution semantics on Windows using the Node.js runtime (V8 engine). It covers value vs reference types, memory allocation (heap-managed objects), copy semantics (shallow vs deep), and nullability (undefined/null). Examples are provided for typical Node.js usage.

Contents


Windows — Run (PowerShell / Command Prompt)

powershell node main.js


Overview

This guide explains how JavaScript (Node.js V8 engine) handles memory and execution semantics on Windows: value vs reference types, memory allocation (heap-managed objects), copy semantics (shallow vs deep), and nullability (undefined/null). Examples are provided for typical Node.js usage.


Contents


1) Data Structures — Primitive vs Object

Example:

let a = 10;
let b = a; // value copy
b = 20; // a remains 10

let obj1 = { x: 1 };
let obj2 = obj1; // reference copy
obj2.x = 5; // obj1.x also 5

Notes: - Strings are immutable; operations create new strings.


2) Storage — V8 Heap & Stack

Windows/Node specifics: - Node.js uses V8's memory management; adjust --max-old-space-size to change heap size. - The event loop drives execution; asynchronous I/O operations do not block JS thread.


3) Copy Semantics — Shallow vs Deep

Example:

const orig = { a: { b: 1 } };
const shallow = { ...orig };
shallow.a.b = 2; // orig.a.b also 2

const deep = structuredClone(orig);
deep.a.b = 3; // orig unchanged

Pitfalls: - JSON-based cloning loses functions, undefined, and special types (Date, Map, Set).


4) Nullability — undefined vs null

Example:

let x;
console.log(x === undefined); // true
x = null;
console.log(x === null); // true

const name = user?.profile?.name ?? 'anonymous';

Best practices: - Prefer undefined for absent values internally and null for intentionally empty API responses, or pick a consistent convention in your codebase.


Examples — Runnable Snippets

main.js:

// primitives vs objects
let n = 1;
let m = n;
m = 2;
console.log(n, m); // 1 2

let o1 = { v: 1 };
let o2 = o1;
o2.v = 9;
console.log(o1.v); // 9

// shallow vs deep
const a = { x: { y: 1 } };
const shallow = { ...a };
shallow.x.y = 5;
console.log(a.x.y); // 5

const deep = structuredClone(a);
deep.x.y = 7;
console.log(a.x.y); // still 5

// nullish
let maybe;
console.log(maybe ?? 'default');

Run with node main.js.


Windows / Node.js Specific Notes


References

End of JavaScript guide.