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: docs/javascript/all-about-variables/hoisting.md
+3-2Lines changed: 3 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -94,7 +94,7 @@ Function expressions are not hoisted in the same way as function declarations. O
94
94
```javascript title="app.js"
95
95
sayHello(); // Throws a TypeError
96
96
97
-
varsayHello=function() {
97
+
varsayHello=function() {
98
98
console.log("Hello, World!");
99
99
};
100
100
```
@@ -118,6 +118,7 @@ By understanding how hoisting works, you can avoid common pitfalls and write mor
118
118
To avoid confusion and potential issues related to hoisting, it's a good practice to declare your variables and functions at the beginning of their containing scope. This makes your code more readable and predictable.
119
119
120
120
**Remember:**
121
+
121
122
- Use `let` and `const` for variable declarations to avoid hoisting-related bugs.
122
123
- Declare functions before calling them to ensure they are hoisted correctly.
123
124
- Be mindful of the TDZ when using `let` and `const` to prevent `ReferenceError` issues.
@@ -129,4 +130,4 @@ Hoisting can feel like magic, but understanding how it works will help you write
129
130
130
131
## Conclusion
131
132
132
-
Hoisting is a unique feature of JavaScript that allows you to access variables and functions before they are declared in your code. By hoisting declarations to the top of their containing scope, JavaScript enables you to write code that might seem out of order but still works as expected.
133
+
Hoisting is a unique feature of JavaScript that allows you to access variables and functions before they are declared in your code. By hoisting declarations to the top of their containing scope, JavaScript enables you to write code that might seem out of order but still works as expected.
Copy file name to clipboardExpand all lines: docs/javascript/all-about-variables/variable-naming-rules.md
+9-6Lines changed: 9 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ description: Learn about the rules and best practices for naming variables in Ja
9
9
10
10
<AdsComponent />
11
11
12
-
When writing JavaScript code, it's essential to follow consistent naming conventions for variables to improve code readability and maintainability. Variable names should be descriptive, meaningful, and follow certain rules to ensure clarity and avoid conflicts.
12
+
When writing JavaScript code, it's essential to follow consistent naming conventions for variables to improve code readability and maintainability. Variable names should be descriptive, meaningful, and follow certain rules to ensure clarity and avoid conflicts.
13
13
14
14
In this tutorial, we'll cover the essential rules for naming variables in JavaScript, along with examples and tips to help you avoid common mistakes.
15
15
@@ -44,11 +44,12 @@ By following the rules and best practices for naming variables, you can write be
44
44
45
45
When naming variables in JavaScript, you need to follow certain rules and conventions to ensure consistency and readability. Here are the essential rules for naming variables:
46
46
47
-
### 1. Variable Names Must Begin with a Letter, Underscore (_), or Dollar Sign ($)
47
+
### 1. Variable Names Must Begin with a Letter, Underscore (\_), or Dollar Sign ($)
48
48
49
49
A variable name can start with any of these three characters:
50
+
50
51
-**Letter**: The first character of a variable name must be a letter (a-z, A-Z) or an uppercase or lowercase letter.
51
-
- Underscore (_): You can use an underscore as the first character of a variable name. It is commonly used to indicate a private or internal variable.
52
+
- Underscore (\_): You can use an underscore as the first character of a variable name. It is commonly used to indicate a private or internal variable.
52
53
- Dollar Sign ($): While the dollar sign can be used in variable names, it is less common and not recommended due to its use in certain JavaScript libraries and frameworks.
53
54
54
55
**Example:**
@@ -58,12 +59,14 @@ let name = "Alice";
58
59
let _count =10;
59
60
let $price =25.99;
60
61
```
62
+
61
63
### 2. Variable Names Can Contain Letters, Numbers, Underscores, and Dollar Signs
62
64
63
65
After the first character, variable names can include:
66
+
64
67
- Letters (a-z, A-Z)
65
68
- Numbers (0-9)
66
-
- Underscores (_)
69
+
- Underscores (\_)
67
70
- Dollar Signs ($)
68
71
69
72
**Examples:**
@@ -130,7 +133,7 @@ let coordinateX = 10;
130
133
131
134
// Acceptable in loops
132
135
for (let i = 0; i < 10; i++) {
133
-
console.log(i);
136
+
console.log(i);
134
137
}
135
138
```
136
139
@@ -216,4 +219,4 @@ By following these guidelines, you can create well-structured, readable, and mai
216
219
217
220
## Conclusion
218
221
219
-
In this tutorial, you learned about the rules and best practices for naming variables in JavaScript. By following these guidelines, you can write clean, consistent, and readable code that is easier to maintain and understand. Remember that choosing meaningful and descriptive variable names is essential for improving code quality, readability, and maintainability.
222
+
In this tutorial, you learned about the rules and best practices for naming variables in JavaScript. By following these guidelines, you can write clean, consistent, and readable code that is easier to maintain and understand. Remember that choosing meaningful and descriptive variable names is essential for improving code quality, readability, and maintainability.
0 commit comments