fix some translate error (#34139)

* fix some translate error

* Update index.md
This commit is contained in:
Johnson
2018-11-25 10:08:43 +08:00
committed by Jingyi Ding
parent a1d25bb90f
commit 1859bc2eab

View File

@ -1,10 +1,10 @@
--- ---
title: Let and Const title: Let and Const
localeTitle: 让和Const localeTitle: let 和 const
--- ---
## ## let
let类似于var但是有范围。 let只能在定义的块级中访问。 let类似于var但是let有作用域。 let只能在定义的块级作用域中访问。
``` ```
if (true) { if (true) {
let a = 40; let a = 40;
@ -29,9 +29,9 @@ let a = 50;
console.log(a); // 50 console.log(a); // 50
``` ```
## 常量 ## const
Const用于为变量赋值常量。价值无法改变。这是固定的 const声明一个常量。常量的值不能修改
``` ```
const a = 50; const a = 50;
a = 60; // shows error. You cannot change the value of const. a = 60; // shows error. You cannot change the value of const.
@ -39,7 +39,7 @@ const a = 50;
b = "Assigning new value"; // shows error. b = "Assigning new value"; // shows error.
``` ```
考虑另一个例子。 另一个例子。
``` ```
const LANGUAGES = ['Js', 'Ruby', 'Python', 'Go']; const LANGUAGES = ['Js', 'Ruby', 'Python', 'Go'];
LANGUAGES = "Javascript"; // shows error. LANGUAGES = "Javascript"; // shows error.
@ -47,6 +47,6 @@ const LANGUAGES = ['Js', 'Ruby', 'Python', 'Go'];
console.log(LANGUAGES); // ['Js', 'Ruby', 'Python', 'Go', 'Java'] console.log(LANGUAGES); // ['Js', 'Ruby', 'Python', 'Go', 'Java']
``` ```
可能有点混乱 可能有点迷惑
以这种方式考虑。无论何时定义const变量Javascript都会将值的地址引用给变量。在我们的示例中变量'LANGUAGES'实际上引用了分配给数组的内存。因此,您无法在以后更改变量以引用其他内存位置。在整个程序中它只引用数组。 换一种方式。无论何时定义const变量Javascript都会将值的地址引用给变量。在我们的示例中变量'LANGUAGES'实际上引用了分配给数组的内存。因此,您无法更改变量以引用其他内存位置。在整个程序中它只引用数组。