-
Notifications
You must be signed in to change notification settings - Fork 22
Variables #13
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
Variables #13
Changes from 1 commit
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 | ||||
---|---|---|---|---|---|---|
@@ -1,21 +1,22 @@ | ||||||
## The variable for 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`,但它可能不夠清楚說明代表是哪個星球。有著更多細節是好的,至少在變數 `沒變得太長` 之前。 | ||||||
|
||||||
## 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. | ||||||
同樣地,若確定 user 就代表現在的使用者,我們也可用 `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. | ||||||
現代化編輯器的自動完成功能讓寫長命名變數變得很簡單,不要忽略這功能,一個名字有三個字節是適當的。 | ||||||
|
||||||
若你的編輯器沒有自動完成功能,快來選 [一個新的](/code-editors) 吧。 | ||||||
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.
Suggested change
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. 我這種引述前後都會留空白耶,比較凸顯得出這邊有什麼東西 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. 喔喔 我以為中文之間可以不用留空 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. 如果是強調用的話 我覺得ok |
||||||
|
||||||
And if your editor does not have proper autocompletion, get [a new one](/code-editors). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
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` 是這樣,所以我們可以讓它使用大寫命名。 | ||
|
||
相對地,`age` 在執行期間才被計算出來。今天我們有一個年齡,一年後就會有另一個。某種程度上它因為不會經由程式碼被改變所以是個常數,但相較於 `birthday` 卻 "沒那麼不變",它是被計算出來的,故我們應該用小寫來命名。 | ||
lenchen1112 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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. |
Uh oh!
There was an error while loading. Please reload this page.