Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5149,3 +5149,35 @@ The condition within the `if` statement checks whether the value of `!typeof ran

</p>
</details>

---

###### 156. What's the output?

```javascript
var a = 20;
let b = 20;

console.log(window.a, window.b);
```

- A: `20 and 20`
- B: `20 and undefined`
- C: `TypeError`
- D: `undefined and undefined`

<details><summary><b>Answer</b></summary>
<p>

#### Answer: B

`var`: Variables declared with var are `function-scoped` or `global-scoped` and become properties of the global object (window in browsers).

`let`: Variables declared with let are `block-scoped` and are not bound to the global object (window).

`var a = 20` makes `a` a property of the window object, so `window.a` returns `20`.

`let b = 20` does not make `b` a property of the window object, so `window.b` returns `undefined`.

</p>
</details>
30 changes: 30 additions & 0 deletions id-ID/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5087,3 +5087,33 @@ Kondisi dalam pernyataan `if` memeriksa apakah nilai dari `!typeof randomValue`
</details>

---

###### 156. Apa hasilnya?

```javascript
var a = 20;
let b = 20;

console.log(window.a, window.b);
```

- A: `20 and 20`
- B: `20 and undefined`
- C: `TypeError`
- D: `undefined and undefined`

<details><summary><b>Jawaban</b></summary>
<p>

#### Answer: B

`var`: Variabel yang dideklarasikan dengan `var` bersifat `function-scoped` atau `global-scoped`, dan menjadi properti dari objek global (window).

`let`: Variabel yang dideklarasikan dengan `let` bersifat `block-scoped` dan tidak terikat ke objek global (window).

`var a = 20` membuat `a` menjadi properti window, sehingga `window.a` mengembalikan `20`.

`let b = 20` tidak membuat `b` menjadi properti window, sehingga `window.b` mengembalikan `undefined`.

</p>
</details>