Agenda
<aside>
📌 Reminders
- Submit lab by September 22, 2024
- A1 out
</aside>
1. JavaScript Modules:
- Why Modules?
- Loaded asynchronously → faster.
- Deferred execution → prevents race conditions.
- Enforces strict mode → reduces bugs.
- How to Upgrade:
- Rename
index.js to index.mjs.
- Update the
<script> tag in index.html to load the module.
2. Local Storage for Data Persistence:
- Local storage allows you to store up to 10 MB in the browser using key-value pairs.
- Example Usage:
- Store data:
localStorage.setItem(key, JSON.stringify(object));
- Retrieve data:
JSON.parse(localStorage.getItem(key));
3. Frontend API Design:
- Separate concerns by having:
- Frontend Controller (
index.mjs) manage the UI.
- Frontend API (
api.mjs) handle data storage and retrieval.
- Example API functions:
getMessages(), addMessage(), deleteMessage().