Final Shop Management JS Report
Final Shop Management JS Report
1. Introduction
JavaScript is a fundamental language in modern web development, offering interactivity and
logic control on the client side. This project, Simple Shop Management System,
demonstrates how core JavaScript concepts can be applied to create a real-world mini-
market management tool. The project is designed to manage daily shop transactions such as
adding products, tracking sales and supplies, and analyzing product performance.
3. Objectives
The objective of this project is to apply and demonstrate mastery over JavaScript
fundamentals. Specifically:
- Use variable declarations with `var`, `let`, and `const`
- Handle string, numeric, and object data types
- Build and reuse functions (traditional and arrow)
- Create and manipulate objects and arrays
- Use array and string methods
- Control logic with if-else and switch-case
- Implement loop structures (forEach)
- Explore Sets and Maps for data summarization
- Understand hoisting and scope
- Implement asynchronous functions with `async/await`
- Use modern JS (arrow functions, DOM interaction, localStorage)
A. Variable Declarations
`var`, `let`, and `const` are all demonstrated. `var` is shown for historical reference.
```javascript
let products = [...];
const form = document.getElementById("product-form");
var oldVariable = "This is var";
```
```javascript
totalSold += parseFloat(p.sold || 0);
const isToday = p.date === today;
```
C. Functions
Both traditional and arrow functions are used.
```javascript
function updateTable() { ... }
const saveToStorage = () => { ... }
```
D. Objects
Each product is stored as a JS object with keys like product, quantity, date, etc.
```javascript
const newProduct = { product, quantity, supplier, ... };
```
```javascript
products.forEach(p => { ... });
const filtered = records.filter(p => p.product.toLowerCase().includes(filter));
```
F. Control Structures
Conditional checks are used for filtering and logic branching.
```javascript
if (editIndex !== null) { ... } else { ... }
if (!map.has(p.date)) map.set(p.date, []);
```
G. Looping Structures
The project uses loops via `forEach()` and `map()`.
```javascript
records.forEach((p, i) => { ... });
```
```javascript
const productTypes = new Set();
const productSalesMap = new Map();
```
J. Hoisting
Functions are defined before use to avoid hoisting issues. The `var` example shows hoisting
implicitly.
```javascript
var oldVariable = "demo";
```
K. Arrow Functions
Used for conciseness and cleaner syntax.
```javascript
form.onsubmit = async (e) => { ... };
const deleteProduct = (index) => { ... };
```
```javascript
const fakeAsyncSave = async () => {
await new Promise(resolve => setTimeout(resolve, 300));
};
```