You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: JavaScript-Quick-Reference.md
+10-11
Original file line number
Diff line number
Diff line change
@@ -815,13 +815,13 @@ In JavaScript, objects are collections of properties, and you can access these p
815
815
816
816
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.
817
817
818
-
####When to Use Dot Notation
818
+
### When to Use Dot Notation
819
819
820
820
-**Known Property Names:** Use dot notation when you know the property name at development time and it is a valid JavaScript identifier.
821
821
-**Clear and Direct Access:** Dot notation is ideal for accessing properties directly and offers a concise syntax for this purpose.
822
822
-**Code Readability:** It enhances code readability, especially when accessing well-known properties of objects.
823
823
824
-
####When to Use Bracket Notation
824
+
### When to Use Bracket Notation
825
825
826
826
-**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.
827
827
-**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
1239
1239
1240
1240
`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.
1241
1241
1242
-
####Generating a Random Number
1242
+
### Generating a Random Number
1243
1243
1244
1244
```javascript
1245
1245
constrandomNumber=Math.random()
@@ -2146,7 +2146,7 @@ In JavaScript, both objects and arrays are used to store collections of data. Ho
2146
2146
2147
2147
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.
2148
2148
2149
-
####When to Use Objects
2149
+
### When to Use Objects
2150
2150
2151
2151
-**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.
2152
2152
-**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 = {
2166
2166
2167
2167
Arrays are ordered collections of values. They are best suited for storing lists of items where order matters.
2168
2168
2169
-
####When to Use Arrays
2169
+
### When to Use Arrays
2170
2170
2171
2171
-**Ordered Data:** Use arrays when the order of your data is important. For example, a list of tasks in a to-do list application.
2172
2172
-**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
2280
2280
2281
2281
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.
2282
2282
2283
-
####HTML5 Validation Attributes
2283
+
### HTML5 Validation Attributes
2284
2284
2285
2285
-**Purpose:** Leverage browser capabilities to perform basic validations without additional code.
2286
2286
-**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
-**Purpose:** Implement complex or custom logic that cannot be achieved with HTML5 attributes alone.
2302
2302
-**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
2343
2343
-**localStorage:** Enables data storage across browser sessions. Data persists until explicitly cleared, making it suitable for storing user preferences or long-term data.
2344
2344
-**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.
2345
2345
2346
-
### Practical Examples
2347
2346
2348
-
####Example 1: Saving User Preferences with localStorage
2347
+
### Example 1: Saving User Preferences with localStorage
2349
2348
2350
2349
**Scenario:** A website allows users to choose a theme. Using localStorage, the selected theme persists across sessions, providing a consistent user experience.
2351
2350
@@ -2366,7 +2365,7 @@ function applySavedTheme() {
2366
2365
applySavedTheme()
2367
2366
```
2368
2367
2369
-
####Example 2: Storing Session Data with sessionStorage
2368
+
### Example 2: Storing Session Data with sessionStorage
2370
2369
2371
2370
**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.
2372
2371
@@ -2383,7 +2382,7 @@ function retrieveFormData(step) {
2383
2382
}
2384
2383
```
2385
2384
2386
-
####Example 3: ShoppingCart Persistence
2385
+
### Example 3: ShoppingCart Persistence
2387
2386
2388
2387
**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.
0 commit comments