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: 1-js/02-first-steps/05-types/article.md
+10-9Lines changed: 10 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -213,14 +213,7 @@ The `symbol` type is used to create unique identifiers for objects. We have to m
213
213
214
214
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.
215
215
216
-
It supports two forms of syntax:
217
-
218
-
1. As an operator: `typeof x`.
219
-
2. As a function: `typeof(x)`.
220
-
221
-
In other words, it works with parentheses or without them. The result is the same.
222
-
223
-
The call to `typeof x` returns a string with the type name:
216
+
A call to `typeof x` returns a string with the type name:
224
217
225
218
```js
226
219
typeofundefined// "undefined"
@@ -254,6 +247,14 @@ The last three lines may need additional explanation:
254
247
2. The result of `typeof null` is `"object"`. That's an officially recognized error in `typeof` behavior, coming from the early days of JavaScript and kept for compatibility. Definitely, `null` is not an object. It is a special value with a separate type of its own.
255
248
3. The result of `typeof alert` is `"function"`, because `alert` is a function. We'll study functions in the next chapters where we'll also see that there's no special "function" type in JavaScript. Functions belong to the object type. But `typeof` treats them differently, returning `"function"`. That also comes from the early days of JavaScript. Technically, such behavior isn't correct, but can be convenient in practice.
256
249
250
+
```smart header="The `typeof(x)` syntax"
251
+
You may also see another syntax in the code: `typeof(x)`. It's the same as `typeof x`.
252
+
253
+
The parentheses here aren't a part of the `typeof` operator. It's the kind of parentheses used for mathematical grouping. Usually, such parentheses contain a mathematical expression, such as `(2 + 2)`, but here they contain only one argument `(x)`. Syntactically, they allow to avoid a space between the `typeof` operator and its argument, and some people like it.
254
+
255
+
Some people prefer `typeof(x)`, although the `typeof x` syntax is much more common.
256
+
```
257
+
257
258
## Summary
258
259
259
260
There are 8 basic data types in JavaScript.
@@ -269,7 +270,7 @@ There are 8 basic data types in JavaScript.
269
270
270
271
The `typeof` operator allows us to see which type is stored in a variable.
271
272
272
-
-Two forms: `typeof x` or`typeof(x)`.
273
+
- Usually used as `typeof x`, but `typeof(x)` is also possible.
273
274
- Returns a string with the name of the type, like `"string"`.
274
275
- For `null` returns `"object"` -- this is an error in the language, it's not actually an object.
0 commit comments