You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33-65Lines changed: 33 additions & 65 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,32 +9,32 @@
9
9
From basic to advanced: test how well you know JavaScript, refresh your knowledge a bit, or prepare for your coding interview! :muscle::rocket: I update this repo regularly with new questions. I added the answers in the **collapsed sections** below the questions, simply click on them to expand it. It's just for fun, good luck! :heart:</span>
@@ -3227,7 +3227,7 @@ With the `||` operator, we can return the first truthy operand. If all values ar
3227
3227
3228
3228
`(false || {} || null)`: the empty object `{}` is a truthy value. This is the first (and only) truthy value, which gets returned. `one` is equal to `{}`.
3229
3229
3230
-
`(null || false || "")`: all operands are falsy values. This means that the past operand, `""` gets returned. `two` is equal to `""`.
3230
+
`(null || false || "")`: all operands are falsy values. This means that the last operand, `""` gets returned. `two` is equal to `""`.
3231
3231
3232
3232
`([] || 0 || "")`: the empty array`[]` is a truthy value. This is the first truthy value, which gets returned. `three` is equal to `[]`.
3233
3233
@@ -3271,7 +3271,7 @@ We can get this value with both `.then` and the `await` keyword in an `async` fu
3271
3271
3272
3272
In the `firstFunction`, we (sort of) put the myPromise function aside while it was running, but continued running the other code, which is `console.log('second')` in this case. Then, the function resolved with the string `I have resolved`, which then got logged after it saw that the callstack was empty.
3273
3273
3274
-
With the await keyword in `secondFunction`, we literally pause the execution of an async function until the value has been resolved befoer moving to the next line.
3274
+
With the await keyword in `secondFunction`, we literally pause the execution of an async function until the value has been resolved before moving to the next line.
3275
3275
3276
3276
This means that it waited for the `myPromise` to resolve with the value `I have resolved`, and only once that happened, we moved to the next line: `second` got logged.
In JavaScript, we have two ways to access properties on an object: bracket notation, or dot notation. In this example, we use dot notation (`colorConfig.colors`) instead of bracket notation (`colorConfig["colors"]`).
3411
3411
3412
-
With dot notation, JavaScript tries to find the property on the object with that exact name. In this example, JavaScript tries to find a property called `colors` on the `colorConfig` object. There is no proprety called `colors`, so this returns `undefined`. Then, we try to access the value of the first element by using `[1]`. We cannot do this on a value that's `undefined`, so it throws a `TypeError`: `Cannot read property '1' of undefined`.
3412
+
With dot notation, JavaScript tries to find the property on the object with that exact name. In this example, JavaScript tries to find a property called `colors` on the `colorConfig` object. There is no property called `colors`, so this returns `undefined`. Then, we try to access the value of the first element by using `[1]`. We cannot do this on a value that's `undefined`, so it throws a `TypeError`: `Cannot read property '1' of undefined`.
3413
3413
3414
3414
JavaScript interprets (or unboxes) statements. When we use bracket notation, it sees the first opening bracket `[` and keeps going until it finds the closing bracket `]`. Only then, it will evaluate the statement. If we would've used `colorConfig[colors[1]]`, it would have returned the value of the `red` property on the `colorConfig` object.
3415
3415
@@ -3471,7 +3471,7 @@ With `splice` method, we modify the original array by deleting, replacing or add
3471
3471
3472
3472
---
3473
3473
3474
-
###### <aname=20191009></a>109. What's the output?
3474
+
###### 109. What's the output?
3475
3475
3476
3476
```javascript
3477
3477
constfood= ['🍕', '🍫', '🥑', '🍔'];
@@ -4466,39 +4466,7 @@ However, it only _shallowly_ freezes the object, meaning that only _direct_ prop
4466
4466
4467
4467
---
4468
4468
4469
-
###### 138. Which of the following will modify the `person` object?
4470
-
4471
-
```javascript
4472
-
constperson= {
4473
-
name:'Lydia Hallie',
4474
-
address: {
4475
-
street:'100 Main St',
4476
-
},
4477
-
};
4478
-
4479
-
Object.freeze(person);
4480
-
```
4481
-
4482
-
- A: `person.name="Evan Bacon"`
4483
-
- B: `deleteperson.address`
4484
-
- C: `person.address.street="101 Main St"`
4485
-
- D: `person.pet= { name:"Mara" }`
4486
-
4487
-
<details><summary><b>Answer</b></summary>
4488
-
<p>
4489
-
4490
-
#### Answer: C
4491
-
4492
-
The `Object.freeze` method _freezes_ an object. No properties can be added, modified, or removed.
4493
-
4494
-
However, it only _shallowly_ freezes the object, meaning that only _direct_ properties on the object are frozen. If the property is another object, like `address` in this case, the properties on that object aren't frozen, and can be modified.
4495
-
4496
-
</p>
4497
-
</details>
4498
-
4499
-
---
4500
-
4501
-
###### 139. What's the output?
4469
+
###### 138. What's the output?
4502
4470
4503
4471
```javascript
4504
4472
constadd=x=>x+x;
@@ -4530,7 +4498,7 @@ Then, we invoked `myFunc(3)` and passed the value `3` as the value for the argum
4530
4498
4531
4499
---
4532
4500
4533
-
###### 140. What's the output?
4501
+
###### 139. What's the output?
4534
4502
4535
4503
```javascript
4536
4504
classCounter {
@@ -4568,7 +4536,7 @@ In ES2020, we can add private variables in classes by using the `#`. We cannot a
4568
4536
4569
4537
---
4570
4538
4571
-
###### 141. What's the output?
4539
+
###### 140. What's missing?
4572
4540
4573
4541
```javascript
4574
4542
constteams= [
@@ -4612,7 +4580,7 @@ If we would've written `yield`, `return yield`, or `return`, the entire generato
4612
4580
4613
4581
---
4614
4582
4615
-
###### 142. What's the output?
4583
+
###### 141. What's the output?
4616
4584
4617
4585
```javascript
4618
4586
constperson= {
@@ -4657,7 +4625,7 @@ After pushing `dancing` and `baking`, the value of `person.hobbies` is `["coding
4657
4625
4658
4626
---
4659
4627
4660
-
###### 143. What's the output?
4628
+
###### 142. What's the output?
4661
4629
4662
4630
```javascript
4663
4631
classBird {
@@ -4693,7 +4661,7 @@ We create the variable `pet` which is an instance of the `Flamingo` class. When
4693
4661
4694
4662
---
4695
4663
4696
-
###### 144. Which of the options result(s) in an error?
4664
+
###### 143. Which of the options result(s) in an error?
4697
4665
4698
4666
```javascript
4699
4667
const emojis = ['🎄', '🎅🏼', '🎁', '⭐'];
@@ -4721,7 +4689,7 @@ The `const` keyword simply means we cannot _redeclare_ the value of that variabl
4721
4689
4722
4690
---
4723
4691
4724
-
###### 145. What do we need to add to the `person` object to get `["Lydia Hallie", 21]` as the output of `[...person]`?
4692
+
###### 144. What do we need to add to the `person` object to get `["Lydia Hallie", 21]` as the output of `[...person]`?
4725
4693
4726
4694
```javascript
4727
4695
const person = {
@@ -4734,7 +4702,7 @@ const person = {
4734
4702
4735
4703
- A: Nothing, object are iterable by default
4736
4704
- B: `*[Symbol.iterator]() { for (let x inthis) yield*this[x] }`
4737
-
- C: `*[Symbol.iterator]() { for (let x inthis) yield*Object.values(this) }`
0 commit comments