Skip to content

Commit 51a0415

Browse files
committed
various content updates and formatting fixes
1 parent 1e27a22 commit 51a0415

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

JavaScript-Quick-Reference.md

+10-11
Original file line numberDiff line numberDiff line change
@@ -815,13 +815,13 @@ In JavaScript, objects are collections of properties, and you can access these p
815815

816816
Dot notation is preferred for direct and straightforward property access when the property name is known at development time and is a valid JavaScript identifier. On the other hand, bracket notation offers more flexibility and versatility, allowing for dynamic property access, handling special cases, and enabling programmatic property access.
817817

818-
#### When to Use Dot Notation
818+
### When to Use Dot Notation
819819

820820
- **Known Property Names:** Use dot notation when you know the property name at development time and it is a valid JavaScript identifier.
821821
- **Clear and Direct Access:** Dot notation is ideal for accessing properties directly and offers a concise syntax for this purpose.
822822
- **Code Readability:** It enhances code readability, especially when accessing well-known properties of objects.
823823

824-
#### When to Use Bracket Notation
824+
### When to Use Bracket Notation
825825

826826
- **Dynamic Property Access:** Use bracket notation when the property name is determined dynamically at runtime, such as when it's stored in a variable or computed through an expression.
827827
- **Handling Special Cases:** Bracket notation is essential for accessing properties with special characters, spaces, or reserved words in JavaScript.
@@ -1239,7 +1239,7 @@ Introduction to JavaScript's Date object, focusing on creating, manipulating, an
12391239

12401240
`Math.random()` is a powerful JavaScript function that generates a pseudo-random number between 0 (inclusive) and 1 (exclusive). This function is widely used in various programming scenarios, from simple tasks like randomizing UI elements to complex simulations and algorithms. Understanding how to effectively use `Math.random()` can add a dynamic and unpredictable element to your applications.
12411241

1242-
#### Generating a Random Number
1242+
### Generating a Random Number
12431243

12441244
```javascript
12451245
const randomNumber = Math.random()
@@ -2146,7 +2146,7 @@ In JavaScript, both objects and arrays are used to store collections of data. Ho
21462146

21472147
Objects are key-value pairs where each key is a string and the value can be anything. They are ideal for storing data with named properties.
21482148

2149-
#### When to Use Objects
2149+
### When to Use Objects
21502150

21512151
- **Descriptive Data:** Use objects when you need to store data with descriptive properties. For example, user profiles, where each property (name, age, email) describes the user.
21522152
- **Unique Keys:** Use objects when each entry has a unique key, and you might need to look up data based on those keys.
@@ -2166,7 +2166,7 @@ const userProfile = {
21662166

21672167
Arrays are ordered collections of values. They are best suited for storing lists of items where order matters.
21682168

2169-
#### When to Use Arrays
2169+
### When to Use Arrays
21702170

21712171
- **Ordered Data:** Use arrays when the order of your data is important. For example, a list of tasks in a to-do list application.
21722172
- **Homogeneous Elements:** Use arrays when you're dealing with a collection of similar items, where each item doesn't need a named key.
@@ -2280,7 +2280,7 @@ Form validation is a critical aspect of web development, ensuring that the data
22802280

22812281
Client-side validation occurs in the browser before the data is submitted to the server. It provides immediate feedback to users and reduces server load.
22822282

2283-
#### HTML5 Validation Attributes
2283+
### HTML5 Validation Attributes
22842284

22852285
- **Purpose:** Leverage browser capabilities to perform basic validations without additional code.
22862286
- **Usage:** Attributes like `required`, `type="email"`, `minlength`, `maxlength`, and `pattern`.
@@ -2296,7 +2296,7 @@ Client-side validation occurs in the browser before the data is submitted to the
22962296
pattern="^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$" />
22972297
```
22982298

2299-
#### JavaScript Custom Validation
2299+
### JavaScript Custom Validation
23002300

23012301
- **Purpose:** Implement complex or custom logic that cannot be achieved with HTML5 attributes alone.
23022302
- **Usage:** JavaScript to create custom validation functions triggered on form events.
@@ -2343,9 +2343,8 @@ Web Storage allows web applications to store data locally within the user's brow
23432343
- **localStorage:** Enables data storage across browser sessions. Data persists until explicitly cleared, making it suitable for storing user preferences or long-term data.
23442344
- **sessionStorage:** Limits data storage to the lifetime of the page session. It's cleared when the tab is closed, ideal for temporary data like form inputs or session-specific data.
23452345

2346-
### Practical Examples
23472346

2348-
#### Example 1: Saving User Preferences with localStorage
2347+
### Example 1: Saving User Preferences with localStorage
23492348

23502349
**Scenario:** A website allows users to choose a theme. Using localStorage, the selected theme persists across sessions, providing a consistent user experience.
23512350

@@ -2366,7 +2365,7 @@ function applySavedTheme() {
23662365
applySavedTheme()
23672366
```
23682367

2369-
#### Example 2: Storing Session Data with sessionStorage
2368+
### Example 2: Storing Session Data with sessionStorage
23702369

23712370
**Scenario:** A multi-step form where user progress should not be lost if the page reloads, but doesn't need to persist beyond the current session.
23722371

@@ -2383,7 +2382,7 @@ function retrieveFormData(step) {
23832382
}
23842383
```
23852384

2386-
#### Example 3: ShoppingCart Persistence
2385+
### Example 3: ShoppingCart Persistence
23872386

23882387
**Scenario:** An e-commerce site uses localStorage to persist the shopping cart contents even after the browser is closed, improving user experience by allowing users to return to their cart at a later time.
23892388

0 commit comments

Comments
 (0)