Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f2bece3

Browse files
authored
Update 02-first-steps/05-types
1 parent d226cd1 commit f2bece3

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

‎1-js/02-first-steps/05-types/article.md‎

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Data types
22

3-
A variable in JavaScript can contain any data. A variable can at one moment be a string and later receive a numeric value:
3+
A variable in JavaScript can contain any data. A variable can at one moment be a string and at another be a number:
44

55
```js
66
// no error
@@ -10,7 +10,7 @@ message = 123456;
1010

1111
Programming languages that allow such things are called "dynamically typed", meaning that there are data types, but variables are not bound to any of them.
1212

13-
There are seven basic data types in JavaScript. Here we'll study the basics, and in the next chapters we'll talk about each of them in detail.
13+
There are seven basic data types in JavaScript. Here, we'll cover them in general and in the next chapters we'll talk about each of them in detail.
1414

1515
## A number
1616

@@ -19,11 +19,11 @@ let n = 123;
1919
n = 12.345;
2020
```
2121

22-
The *number* type serves both for integer and floating point numbers.
22+
The *number* type represents both integer and floating point numbers.
2323

24-
There are many operations for numbers, e.g. multiplication `*`, division `/`, addition `+`, subtraction `-` and so on.
24+
There are many operations for numbers, e.g. multiplication `*`, division `/`, addition `+`, subtraction `-`, and so on.
2525

26-
Besides regular numbers, there are so-called "special numeric values" which also belong to that type: `Infinity`, `-Infinity` and `NaN`.
26+
Besides regular numbers, there are so-called "special numeric values" which also belong to this data type: `Infinity`, `-Infinity` and `NaN`.
2727

2828
- `Infinity` represents the mathematical [Infinity](https://en.wikipedia.org/wiki/Infinity) ∞. It is a special value that's greater than any number.
2929

@@ -33,7 +33,7 @@ Besides regular numbers, there are so-called "special numeric values" which also
3333
alert( 1 / 0 ); // Infinity
3434
```
3535

36-
Or just mention itin the code directly:
36+
Or just reference it directly:
3737

3838
```js run
3939
alert( Infinity ); // Infinity
@@ -44,27 +44,27 @@ Besides regular numbers, there are so-called "special numeric values" which also
4444
alert( "not a number" / 2 ); // NaN, such division is erroneous
4545
```
4646

47-
`NaN` is sticky. Any further operation on `NaN` would give `NaN`:
47+
`NaN` is sticky. Any further operation on `NaN` returns `NaN`:
4848

4949
```js run
5050
alert( "not a number" / 2 + 5 ); // NaN
5151
```
5252

53-
So, if there's `NaN` somewhere in a mathematical expression, it propagates to the whole result.
53+
So, if there's a `NaN` somewhere in a mathematical expression, it propagates to the whole result.
5454
5555
```smart header="Mathematical operations are safe"
56-
Doing maths is safe in JavaScript. We can do anything: divide by zero, treat non-numeric strings as numbers, etc.
56+
Doing maths is "safe" in JavaScript. We can do anything: divide by zero, treat non-numeric strings as numbers, etc.
5757
58-
The script will never stop with a fatal error ("die"). At worst we'll get `NaN` as the result.
58+
The script will never stop with a fatal error ("die"). At worst, we'll get `NaN` as the result.
5959
```
6060

61-
Special numeric values formally belong to the "number" type. Of course they are not numbers in a common sense of this word.
61+
Special numeric values formally belong to the "number" type. Of course they are not numbers in the common sense of this word.
6262

6363
We'll see more about working with numbers in the chapter <info:number>.
6464

6565
## A string
6666

67-
A string in JavaScript must be quoted.
67+
A string in JavaScript must be surrounded by quotes.
6868

6969
```js
7070
let str = "Hello";
@@ -92,9 +92,9 @@ alert( `Hello, *!*${name}*/!*!` ); // Hello, John!
9292
alert( `the result is *!*${1 + 2}*/!*` ); // the result is 3
9393
```
9494

95-
The expression inside `${...}` is evaluated and the result becomes a part of the string. We can put anything there: a variable like `name` or an arithmetical expression like `1 + 2` or something more complex.
95+
The expression inside `${...}` is evaluated and the result becomes a part of the string. We can put anything in there: a variable like `name` or an arithmetical expression like `1 + 2` or something more complex.
9696

97-
Please note that this can only be done in backticks. Other quotes do not allow such embedding!
97+
Please note that this can only be done in backticks. Other quotes don't have this embedding functionality!
9898
```js run
9999
alert( "the result is ${1 + 2}" ); // the result is ${1 + 2} (double quotes do nothing)
100100
```
@@ -128,31 +128,31 @@ let isGreater = 4 > 1;
128128
alert( isGreater ); // true (the comparison result is "yes")
129129
```
130130

131-
We'll cover booleans more deeply later in the chapter <info:logical-operators>.
131+
We'll cover booleans more deeply in the chapter <info:logical-operators>.
132132

133133
## The "null" value
134134

135-
The special `null` value does not belong to any type of those described above.
135+
The special `null` value does not belong to any of the types described above.
136136

137-
It forms a separate type of its own, which contains only the `null` value:
137+
It forms a separate type of its own which contains only the `null` value:
138138

139139
```js
140140
let age = null;
141141
```
142142

143-
In JavaScript `null` is not a "reference to a non-existing object" or a "null pointer" like in some other languages.
143+
In JavaScript, `null` is not a "reference to a non-existing object" or a "null pointer" like in some other languages.
144144

145-
It's just a special value which has the sense of "nothing", "empty" or "value unknown".
145+
It's just a special value which represents "nothing", "empty" or "value unknown".
146146

147-
The code above states that the `age` is unknown or empty for some reason.
147+
The code above states that `age` is unknown or empty for some reason.
148148

149149
## The "undefined" value
150150

151-
The special value `undefined` stands apart. It makes a type of its own, just like `null`.
151+
The special value `undefined` also stands apart. It makes a type of its own, just like `null`.
152152

153153
The meaning of `undefined` is "value is not assigned".
154154

155-
If a variable is declared, but not assigned, then its value is exactly `undefined`:
155+
If a variable is declared, but not assigned, then its value is `undefined`:
156156

157157
```js run
158158
let x;
@@ -170,26 +170,26 @@ x = undefined;
170170
alert(x); // "undefined"
171171
```
172172

173-
...But it's not recommended to do that. Normally, we use `null` to write an "empty" or an "unknown" value into the variable, and `undefined` is only used for checks, to see if the variable is assigned or similar.
173+
...But we don't recommend doing that. Normally, we use `null` to assign an "empty" or "unknown" value to a variable, and we use `undefined` for checks like seeing if a variable has been assigned.
174174

175175
## Objects and Symbols
176176

177177
The `object` type is special.
178178

179-
All other types are called "primitive", because their values can contain only a single thing (be it a string or a number or whatever). In contrast, objects are used to store collections of data and more complex entities. We'll deal with them later in the chapter <info:object> after we know enough about primitives.
179+
All other types are called "primitive" because their values can contain only a single thing (be it a string or a number or whatever). In contrast, objects are used to store collections of data and more complex entities. We'll deal with them later in the chapter <info:object> after we learn more about primitives.
180180

181-
The `symbol` type is used to create unique identifiers for objects. We have to mention it here for completeness, but it's better to study them after objects.
181+
The `symbol` type is used to create unique identifiers for objects. We have to mention it here for completeness, but it's better to study this type after objects.
182182

183183
## The typeof operator [#type-typeof]
184184

185-
The `typeof` operator returns the type of the argument. It's useful when we want to process values of different types differently, or just want to make a quick check.
185+
The `typeof` operator returns the type of the argument. It's useful when we want to process values of different types differently or just want to do a quick check.
186186

187187
It supports two forms of syntax:
188188

189189
1. As an operator: `typeof x`.
190-
2. Function style: `typeof(x)`.
190+
2. As a function: `typeof(x)`.
191191

192-
In other words, it works both with parentheses or without them. The result is the same.
192+
In other words, it works with parentheses or without them. The result is the same.
193193

194194
The call to `typeof x` returns a string with the type name:
195195

@@ -217,11 +217,11 @@ typeof alert // "function" (3)
217217
*/!*
218218
```
219219

220-
The last three lines may need additional explanations:
220+
The last three lines may need additional explanation:
221221

222-
1. `Math` is a built-in object that provides mathematical operations. We will learn it in the chapter <info:number>. Here it serves just as an example of an object.
223-
2. The result of `typeof null` is `"object"`. That's wrong. It is an officially recognized error in `typeof`, kept for compatibility. Of course, `null` is not an object. It is a special value with a separate type of its own. So, again, that's an error in the language.
224-
3. The result of `typeof alert` is `"function"`, because `alert` is a function of the language. We'll study functions in the next chapters, and we'll see that there's no special "function" type in the language. Functions belong to the object type. But `typeof` treats them differently. Formally, it's incorrect, but very convenient in practice.
222+
1. `Math` is a built-in object that provides mathematical operations. We will learn it in the chapter <info:number>. Here, it serves just as an example of an object.
223+
2. The result of `typeof null` is `"object"`. That's wrong. It is an officially recognized error in `typeof`, kept for compatibility. Of course, `null` is not an object. It is a special value with a separate type of its own. So, again, this is an error in the language.
224+
3. The result of `typeof alert` is `"function"`, because `alert` is a function of the language. We'll study functions in the next chapters where we'll see that there's no special "function" type in JavaScript. Functions belong to the object type. But `typeof` treats them differently. Formally, it's incorrect, but very convenient in practice.
225225

226226

227227
## Summary
@@ -236,10 +236,10 @@ There are 7 basic types in JavaScript.
236236
- `object` for more complex data structures.
237237
- `symbol` for unique identifiers.
238238

239-
The `typeof` operator allows us to see which type is stored in the variable.
239+
The `typeof` operator allows us to see which type is stored in a variable.
240240

241241
- Two forms: `typeof x` or `typeof(x)`.
242242
- Returns a string with the name of the type, like `"string"`.
243-
- For `null` returns `"object"` -- that's an error in the language, it's not an object in fact.
243+
- For `null` returns `"object"` -- this is an error in the language, it's not actually an object.
244244

245-
In the next chapters we'll concentrate on primitive values and once we're familiar with them, then we'll move on to objects.
245+
In the next chapters, we'll concentrate on primitive values and once we're familiar with them, we'll move on to objects.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /