change var to let (#23172)

change var to let
This commit is contained in:
Szymon Woźny
2018-12-23 09:04:10 +01:00
committed by Huyen Nguyen
parent b344ca8602
commit b2ab72cb0b

View File

@ -18,14 +18,15 @@ for (variable in object) {
## Examples
```js
// Initialize object.
var a = { "a": "Athens", "b": "Belgrade", "c": "Cairo" };
const a = { "a": "Athens", "b": "Belgrade", "c": "Cairo" };
// Iterate over the properties.
var s = "";
for (var key in a) {
s += key + ": " + a[key];
s += "<br />";
let s = "";
for (let key in a) {
s += key + ": " + a[key];
s += "<br />";
}
document.write (s);
// Output:
@ -34,15 +35,15 @@ document.write (s);
// c: Cairo
// Initialize the array.
var arr = new Array("zero", "one", "two");
let arr = new Array("zero", "one", "two");
// Add a few expando properties to the array.
arr["orange"] = "fruit";
arr["carrot"] = "vegetable";
// Iterate over the properties and elements.
var s = "";
for (var key in arr) {
let s = "";
for (let key in arr) {
s += key + ": " + arr[key];
s += "<br />";
}