Skip to content

1-js/02-first-steps/04-variables#32

Merged
leviding merged 7 commits intozh-hansfrom
transfer/variables
Apr 23, 2018
Merged

1-js/02-first-steps/04-variables#32
leviding merged 7 commits intozh-hansfrom
transfer/variables

Conversation

@linhe0x0
Copy link
Copy Markdown

@linhe0x0 linhe0x0 commented Apr 9, 2018

Co-authored-by: maoxiaoke thebigyellowbee@qq.com

Cc @maoxiaoke

resolve #4

Co-authored-by: maoxiaoke <thebigyellowbee@qq.com>

resolve #4
@linhe0x0 linhe0x0 changed the title 1-js/02-first-steps/04-variables [WIP] 1-js/02-first-steps/04-variables Apr 11, 2018
@leviding leviding added the WIP Work in process label Apr 12, 2018
@linhe0x0 linhe0x0 removed the WIP Work in process label Apr 17, 2018
@linhe0x0 linhe0x0 changed the title [WIP] 1-js/02-first-steps/04-variables 1-js/02-first-steps/04-variables Apr 17, 2018
@linhe0x0 linhe0x0 self-assigned this Apr 17, 2018
@allenlongbaobao
Copy link
Copy Markdown
Contributor

校对认领

@leviding
Copy link
Copy Markdown
Member

@allenlongbaobao ok

@Starriers
Copy link
Copy Markdown
Contributor

校对认领 @leviding

Copy link
Copy Markdown
Contributor

@Starriers Starriers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sqrthree @leviding 校对完成


```js run
let admin, name; // can declare two variables at once
let admin, name; // 一次定义两个变量。
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

定义 =》 声明
declare 一般翻译为声明,下同

4. Show the value of `admin` using `alert` (must output "John").
1. 定义两个变量:`admin` `name`
2. 将值 `"John"` 赋给 `name`
3. `name` 变量中拷贝其值给 `admin`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

也可以这样翻译 : 将 name 的变量值拷贝给 admin

```

Again, we could shorten that to `userName` if we know for sure that the user is current.
再一次,如果我们的确直到用户就是当前的用户的话,我们可以使用更短的 `userName`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

再一次 =》 还有
直到 =》 知道

再一次,如果我们的确直到用户就是当前的用户的话,我们可以使用更短的 `userName`

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.
现代编辑器可自动补全可以让长变量名变得容易书写。不要节省它们。一个名字中包含三个词就挺好的。
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

第一个 可 =》的
不要节省它们 =》 不要浪费这个特性。 感觉更好些。

@linhe0x0
Copy link
Copy Markdown
Author

@allenlongbaobao 不要忘了来校对啊

sqrtthree and others added 3 commits April 23, 2018 10:52
```

Now we can put some data into it by using the assignment operator `=`:
现在,通过赋值操作符 `=` 为变量添加一些数据。
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

结尾用分号?

```

...Or even in the "comma-first" style:
...甚至使用 “逗号优先” 的形式:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是不是不需要空格?

有一长串的保留字无法用作变量命名,因为它们被语言本身采用了。

For example, words `let`, `class`, `return`, `function` are reserved.
比如,单词 `let` `class` `return` `function` 被保留。
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

多了三个空格

```

Variables declared using `const` are called "constants". They cannot be changed. An attempt to do it would cause an error:
使用 `const` 声明的变量称为 “常量”。它们不能被修改,尝试这样做就会造成错误:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

声明的变量称为后多了一个空格

`pageLoadTime` 的值在页面加载之前是未知的,所以采用常规命名。但是它仍然是个常量,因为赋值之后不会改变。

In other words, capital-named constants are only used as aliases for "hard-coded" values.
换句话说,大写命名的常量仅用作 “硬编码” 值的别名。
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

多两个空格

- `let` -- is a modern variable declaration. The code must be in strict mode to use `let` in Chrome (V8).
- `var` -- is an old-school variable declaration. Normally we don't use it at all, but we'll cover subtle differences from `let` in the chapter <info:var>, just in case you need them.
- `const` -- is like `let`, but the value of the variable can't be changed.
- `let` -- 新时代的变量声明方式。Chrome(V8) 中代码必须开启严格模式以使用 `let`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最后的句号前多一个空格

- `let` -- is a modern variable declaration. The code must be in strict mode to use `let` in Chrome (V8).
- `var` -- is an old-school variable declaration. Normally we don't use it at all, but we'll cover subtle differences from `let` in the chapter <info:var>, just in case you need them.
- `const` -- is like `let`, but the value of the variable can't be changed.
- `let` -- 新时代的变量声明方式。Chrome(V8) 中代码必须开启严格模式以使用 `let`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chrome(V8)后多一个空格

- `const` -- is like `let`, but the value of the variable can't be changed.
- `let` -- 新时代的变量声明方式。Chrome(V8) 中代码必须开启严格模式以使用 `let`
- `var` -- 旧时代的变量声明方式。一般情况下,我们不会使用它。但是,我们会在 <info:var> 章节介绍 `var` 和 `let` 的微妙差别,以防你需要它们。
- `const` -- 类似于`let`, 但是变量的值无法被修改。
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

逗号用全角,不要多空格

Signed-off-by: sqrtthree <imsqrtthree@gmail.com>
@linhe0x0
Copy link
Copy Markdown
Author

@leviding Sorry, 之前转移文章的时候光顾着对内容,忽略排版了。现在已经调好了。

@leviding leviding merged commit c94c2e1 into zh-hans Apr 23, 2018
@leviding leviding deleted the transfer/variables branch April 23, 2018 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants