Conversation
Co-authored-by: maoxiaoke <thebigyellowbee@qq.com> resolve #5
Contributor
|
校对认领 |
Starriers
reviewed
Apr 23, 2018
| **number** 类型用于整数和浮点数。 | ||
|
|
||
| There are many operations for numbers, e.g. multiplication `*`, division `/`, addition `+`, subtraction `-` and so on. | ||
| 数字有很多操作,比如,乘法 `*`,除法 `/`,加法 `+`,减法 `-` 等等。 |
| The `typeof` operator allows us to see which type is stored in the variable. | ||
| - 两种形式: `typeof x` 或者 `typeof(x)`。 | ||
| - 返回的类型的字符串,比如 `"string"`。 | ||
| - `null` 返回 `"object"` -- 这是语言中的一个错误,实际上它并不是一个对象。 |
| - `number` 用于任何类型的数字: 整数或者浮点数。 | ||
| - `string` 用于字符串。一个字符串可以包含一个或多个字符,所以没有单独的单字符类型。 | ||
| - `boolean` 用于 `true` 和 `false`。 | ||
| - `null` 用于未知的值 -- 只有一个 `null` 值的独立类型。 |
| - `string` 用于字符串。一个字符串可以包含一个或多个字符,所以没有单独的单字符类型。 | ||
| - `boolean` 用于 `true` 和 `false`。 | ||
| - `null` 用于未知的值 -- 只有一个 `null` 值的独立类型。 | ||
| - `undefined` 用于未定义的值 -- 只有一个 `undefined` 值的独立类型。 |
| - `undefined` for unassigned values -- a standalone type that has a single value `undefined`. | ||
| - `object` for more complex data structures. | ||
| - `symbol` for unique identifiers. | ||
| `typeof` 运算符可以查看变量的类型。 |
| 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. | ||
| 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. | ||
| 1. `Math` 是一个提供数学运算的内建对象。我们会在章节 <info:number> 学习它。此处作为一个对象的例子。 | ||
| 2. `typeof null` 的结果是 `"object"`。这是不对的。这是一个官方承认的错误,为了兼容性而保留。当然,`null` 不是一个对象。它有自己的类型,是一个特殊值。再次强调,这是语言中的一个错误。 |
Contributor
There was a problem hiding this comment.
这是一个官方承认的错误 =》这是官方在 typeof 方面承认的错误
| 2. `typeof null` 的结果是 `"object"`。这是不对的。这是一个官方承认的错误,为了兼容性而保留。当然,`null` 不是一个对象。它有自己的类型,是一个特殊值。再次强调,这是语言中的一个错误。 | ||
| 3. `typeof alert` 的结果是 `"function"`,因为 `alert` 在语言中是一个函数。我们会在下一章学习函数,那时我们会了解到,在语言中没有一个特别的 “function” 类型。函数隶属于 object 类型。但是 `typeof` 对函数区分对待。这不正确,但在实践中非常方便。 | ||
|
|
||
| ## 总结 |
| `object` 类型是特殊的类型。 | ||
|
|
||
| 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. | ||
| 其他所有的类型都称为“原始类型”,因为它们的值只包含一个单独的东西(字符串、数字或者其他)。相反,对象用于储存数据集合和更复杂的实体。在充分了解原始类型之后,我们会在章节 <info:object> 介绍对象。 |
| 双引号和单引号都是“简单”引用,在 JavaScript 中两者并没有什么差别。 | ||
|
|
||
| Backticks are "extended functionality" quotes. They allow us to embed variables and expressions into a string by wrapping them in `${…}`, for example: | ||
| 反引号是*功能扩展*的引用,允许通过`${…}`, 将变量和表达式嵌入到字符串中。例如: |
Contributor
There was a problem hiding this comment.
功能扩展 用加粗方式
后面的 要空格
将 不要空格
Author
|
@leviding Done. |
leviding
approved these changes
Apr 24, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Co-authored-by: maoxiaoke thebigyellowbee@qq.com
Cc @maoxiaoke
resolve #5