JS Concepts Breakdown Report
JS Concepts Breakdown Report
Breakdown
Project: Simple Shop Management
Below is a detailed explanation of how each JavaScript concept (A–K) was applied in the
project.
A. Variable Declarations
We used `let` and `const` properly across the project:
- `const form = document.getElementById('product-form')` defines fixed references to DOM
elements.
- `let products = []` is declared with `let` since the array will be updated.
- `let editIndex = null` is used to track the editing state.
C. Functions
- Traditional function: `function updateTable() {...}` handles table rendering.
- Arrow function: `form.onsubmit = (e) => {...}` is used for event handling.
- Other arrow functions handle product editing and chart rendering.
D. Objects
- Products are stored as JavaScript objects in an array. Each object has keys like:
`{ product, quantity, supplier, type, sold, soldPrice, date, soldTime, suppliedTime }`.
- New product objects are pushed to the `products[]` array.
F. Control Structures
- `if (editIndex !== null)` determines whether to edit or add a new entry.
- `if (p.date !== today) return;` ensures only today's data is shown.
G. Looping Structures
- `forEach()` is used to process product data.
- Looping helps calculate totals and fill the chart data.
J. Hoisting
- Variables are declared at the top before use to avoid hoisting issues.
- Functions like `updateTable()` and `renderChart()` are defined before they are used to
maintain clarity.
K. Arrow Functions
- Used extensively for concise function expressions:
`const deleteProduct = index => {...}`, `form.onsubmit = e => {...}`