Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 909871d

Browse files
committed
Question 76
1 parent 71110d1 commit 909871d

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

‎README.md‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3079,3 +3079,55 @@ The correct answer is D, and btw "happy new year"!
30793079
30803080
</p>
30813081
</details>
3082+
3083+
3084+
###### 76. What's the output?
3085+
3086+
```javascript
3087+
const address = {
3088+
name: 'hoccoban.com',
3089+
author: 'Vuong Nguyen',
3090+
}
3091+
3092+
const key = Reflect.has(address, 'author') ? Reflect.ownKeys(address)[0] : "hello";
3093+
3094+
Reflect.set(address, 'language', 'JavaScript');
3095+
3096+
const totalKeys = Reflect.ownKeys(address).length;
3097+
3098+
const name = Reflect.get(address, key).length;
3099+
3100+
const language = Reflect.get(address, 'language').length
3101+
3102+
console.log(totalKeys + name + language);
3103+
3104+
```
3105+
- A: 22
3106+
- B: 10
3107+
- C: 20
3108+
- D: 25
3109+
3110+
<details><summary><b>Answer</b></summary>
3111+
<p>
3112+
3113+
The correct answer is D. Why? Now let break it down:
3114+
3115+
- `Reflect.has(address, 'author')` gives us `true` given that the object `address` has the key `author`. Simple as it is. So the value of the variable `key` is now `Reflect.ownKeys(address)[0]`, which in fact is the key `name`.
3116+
3117+
- `Reflect.set(address, 'language', 'JavaScript');` set another key-value to the object `address`.
3118+
3119+
- `Reflect.ownKeys(address).length;` gives us 3 because now it has three keys, so `totalKeys` is now 3.
3120+
3121+
- `Reflect.get(address, key).length;` gives us the length of the string `hoccoban.com` which is 12.
3122+
3123+
- `Reflect.get(address, 'language').length` is the length of the string `JavaScript`, which is 10.
3124+
3125+
- The final answer is 3 + 12 + 10 = 25.
3126+
3127+
#### Answer: D
3128+
3129+
3130+
3131+
</p>
3132+
</details>
3133+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /