New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1-js/02-first-steps/04-variables #32
Changes from 3 commits
8a87fa2
fc12a76
72d8d78
ae43459
df4b679
6217e5a
b65a901
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,9 @@ importance: 2 | |
|
||
--- | ||
|
||
# Working with variables | ||
# 使用变量 | ||
|
||
1. Declare two variables: `admin` and `name`. | ||
2. Assign the value `"John"` to `name`. | ||
3. Copy the value from `name` to `admin`. | ||
4. Show the value of `admin` using `alert` (must output "John"). | ||
1. 定义两个变量:`admin` 和 `name`。 | ||
2. 将值 `"John"` 赋给 `name`。 | ||
3. 从 `name` 变量中拷贝其值给 `admin`。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 也可以这样翻译 : 将 |
||
4. 使用 `alert` 显示 `admin` 的值(一定会输出 "John")。 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
First, the variable for the name of our planet. | ||
首先,定义变量代表我们星球的名字。 | ||
|
||
That's simple: | ||
这很简单: | ||
|
||
```js | ||
let ourPlanetName = "Earth"; | ||
``` | ||
|
||
Note, we could use a shorter name `planet`, but it might be not obvious what planet it refers to. It's nice to be more verbose. At least until the variable isNotTooLong. | ||
注意,我们也可以用一个更短的名字 `planet`,但是它可能并不清楚它指的是什么行星。再啰嗦一点也是挺好的。至少直到这个变量“不太长”就行。 | ||
|
||
Second, the name of the current visitor: | ||
第二,定义当前浏览者的名字: | ||
|
||
```js | ||
let currentUserName = "John"; | ||
``` | ||
|
||
Again, we could shorten that to `userName` if we know for sure that the user is current. | ||
再一次,如果我们的确直到用户就是当前的用户的话,我们可以使用更短的 `userName`。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 再一次 =》 还有 |
||
|
||
Modern editors and autocomplete make long variable names easy to write. Don't save on them. A name with 3 words in it is fine. | ||
现代编辑器可自动补全可以让长变量名变得容易书写。不要节省它们。一个名字中包含三个词就挺好的。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 第一个 可 =》的 |
||
|
||
And if your editor does not have proper autocompletion, get [a new one](/editors). | ||
如果你的编辑器没有合适的自动补全,换[一个新的吧](/editors)。 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
We generally use upper case for constants that are "hard-coded". Or, in other words, when the value is known prior to execution and directly written into the code. | ||
我们通常用大写字母表示“硬编码”的常量。或者,换句话说,当值在执行之前被知道并直接写入代码中的时候。 | ||
|
||
In this code, `birthday` is exactly like that. So we could use the upper case for it. | ||
在这个代码中 `birthday` 确信是这样的。因此我们可以使用大写。 | ||
|
||
In contrast, `age` is evaluated in run-time. Today we have one age, a year after we'll have another one. It is constant in a sense that it does not change through the code execution. But it is a bit "less of a constant" than `birthday`, it is calculated, so we should keep the lower case for it. | ||
在对照组中,`age` 是在运行时计算出的。今天我们有一个年龄,一年以后我们就会有另一个。它在某种意义上不会通过代码的执行而改变。但是相比 `birthday` 它是“少一些常量”的,它是计算出的,因此我们应该使用小写。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
定义 =》 声明
declare 一般翻译为声明,下同