Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Modules and JSON: Programs Across Files (Summary)

Dana’s budget tracker is finished, and so is this course.

What You Learned

In this course, you learned how to:

  • Turn data into JSON text and back, fixing what JSON changes
  • Save a program’s data in a JSON file and load it again
  • Split a program into modules, with one job per file
  • Predict how modules load and what their importers share
  • Make deep copies and compare records value by value
  • Build a program in several files that keeps its data in JSON

Dana’s Tracker, Piece by Piece

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 Dana’s tracker is finished, and so is this course. In this course, you learned how to turn data into JSON text and back, fixing what JSON changes. To save a program’s data in a JSON file and load it again.

00:14 To split a program into modules, with one job per file. To predict how modules load and what their importers share. To make deep copies and compare records value by value.

00:26 And to build a program in several files that keeps its data in JSON.

00:32 First, JSON turned Dana’s records into text a file can hold. Dana typed one amount in quotes by hand. Loading them back, you turned each date string into a Date object, and the quoted 38 into a number.

00:47 Next, the tracker split into files with one job each, and main.js wired them together.

00:55 Last, a spread copy shared the limits, but structuredClone made a what-if budget that’s separate all the way down. Her real budget stayed unchanged, and the tracker prints the proof.

01:07 Here are the things to remember. JSON is text, so parse it, restore the dates, and convert quoted amounts. Give each file one job, and keep main.js thin. A module runs once, and every file that imports it shares its exports.

01:27 Spread copies only one level, while structuredClone copies every level of plain data. Compare flat records key by key with Object.is, because a copy is never the same object as its original.

01:43 To keep going, RealJS has reference pages on ES modules and JSON. The article JSON versus XML shows where each format fits.

01:55 Thanks for watching.

Become a Member to join the conversation.