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
Conversation
Co-authored-by: maoxiaoke <thebigyellowbee@qq.com> resolve #4
校对认领 |
校对认领 @leviding |
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.
|
||
```js run | ||
let admin, name; // can declare two variables at once | ||
let admin, name; // 一次定义两个变量。 |
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 一般翻译为声明,下同
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 comment
The reason will be displayed to describe this comment to others. Learn more.
也可以这样翻译 : 将 name
的变量值拷贝给 admin
|
||
```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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
第一个 可 =》的
不要节省它们 =》 不要浪费这个特性。 感觉更好些。
@allenlongbaobao 不要忘了来校对啊 |
Signed-off-by: sqrtthree <imsqrtthree@gmail.com>
|
||
```js | ||
let message; | ||
``` | ||
|
||
Now we can put some data into it by using the assignment operator `=`: | ||
现在,通过赋值操作符 `=` 为变量添加一些数据。 |
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.
结尾用分号?
```js no-beautify | ||
let user = 'John', | ||
age = 25, | ||
message = 'Hello'; | ||
``` | ||
|
||
...Or even in the "comma-first" style: | ||
...甚至使用 “逗号优先” 的形式: |
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.
是不是不需要空格?
|
||
For example, words `let`, `class`, `return`, `function` are reserved. | ||
比如,单词 `let`, `class`, `return`, `function` 被保留。 |
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.
多了三个空格
|
||
```js | ||
const myBirthday = '18.04.1982'; | ||
``` | ||
|
||
Variables declared using `const` are called "constants". They cannot be changed. An attempt to do it would cause an error: | ||
使用 `const` 声明的变量称为 “常量”。它们不能被修改,尝试这样做就会造成错误: |
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.
声明的变量称为后多了一个空格
|
||
In other words, capital-named constants are only used as aliases for "hard-coded" values. | ||
换句话说,大写命名的常量仅用作 “硬编码” 值的别名。 |
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.
多两个空格
- `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` 。 |
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.
最后的句号前多一个空格
- `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` 。 |
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.
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`, 但是变量的值无法被修改。 |
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.
逗号用全角,不要多空格
Signed-off-by: sqrtthree <imsqrtthree@gmail.com>
@leviding Sorry, 之前转移文章的时候光顾着对内容,忽略排版了。现在已经调好了。 |
Co-authored-by: maoxiaoke thebigyellowbee@qq.com
Cc @maoxiaoke
resolve #4