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
- Change wording in first paragraph, and break out examples into numbered bullets.
- Change some articles and words to make sentences clearer and more consistent.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/04-variables/article.md
+7-5Lines changed: 7 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,10 @@
1
1
# Variables
2
2
3
-
Most of the time, a script needs to work with information. If it's an online-shop -- that's going to be the goods and a shopping cart. If it's a chat -- users, messages and so on.
3
+
Most of the time, a JavaScript application needs to work with information. Here are 2 examples:
4
+
1. An online-shop -- the information might include goods being sold and a shopping cart.
5
+
2. A chat application -- the information might include users, messages, and much more.
4
6
5
-
Variables are used to store the information.
7
+
Variables are used to store this information.
6
8
7
9
[cut]
8
10
@@ -296,7 +298,7 @@ Please name the variables sensibly. Take time to think if needed.
296
298
297
299
Variable naming is one of the most important and complex skills in programming. A quick glance at variable names can reveal which code is written by a beginner and which by an experienced developer.
298
300
299
-
In a real project, most of the time is spent on modifying and extending the existing code base, rather than writing something completely separate from the scratch. And when we return to the code after some time of doing something else, it's much easier to find information that is well-labelled. Or, in other words, when the variables have good names.
301
+
In a real project, most of the time is spent on modifying and extending the existing code base, rather than writing something completely separate from scratch. And when we return to the code after some time of doing something else, it's much easier to find information that is well-labelled. Or, in other words, when the variables have good names.
300
302
301
303
Please spend some time thinking about the right name for a variable before declaring it. That will repay you a lot.
302
304
@@ -305,14 +307,14 @@ Some good-to-follow rules are:
305
307
- Use human-readable names like `userName` or `shoppingCart`.
306
308
- Stay away from abbreviations or short names like `a`, `b`, `c`, unless you really know what you're doing.
307
309
- Make the name maximally descriptive and concise. Examples of bad names are `data` and `value`. Such a name says nothing. It is only ok to use them if it's exceptionally obvious from the context which data or value is meant.
308
-
- Agree on terms within the team and in your own mind. If a site visitor is called a "user" then we should name related variables like `currentUser` or `newUser`, but not `currentVisitor` or a `newManInTown`.
310
+
- Agree on terms within your team and in your own mind. If a site visitor is called a "user" then we should name related variables like `currentUser` or `newUser`, but not `currentVisitor` or a `newManInTown`.
309
311
310
312
Sounds simple? Indeed it is, but creating good descriptive-and-concise names in practice is not. Go for it.
311
313
312
314
```smart header="Reuse or create?"
313
315
And the last note. There are some lazy programmers who, instead of declaring a new variable, tend to reuse the existing ones.
314
316
315
-
As the result, the variable is like a box where people throw different things without changing the sticker. What is inside it now? Who knows... We need to come closer and check.
317
+
As a result, the variable is like a box where people throw different things without changing the sticker. What is inside it now? Who knows... We need to come closer and check.
316
318
317
319
Such a programmer saves a little bit on variable declaration, but loses ten times more on debugging the code.
0 commit comments