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
+171Lines changed: 171 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4745,3 +4745,174 @@ Objects aren't iterable by default. An iterable is an iterable if the iterator p
4745
4745
</p>
4746
4746
</details>
4747
4747
4748
+
---
4749
+
4750
+
###### 146. What's the output?
4751
+
4752
+
```javascript
4753
+
letcount=0;
4754
+
constnums= [0, 1, 2, 3];
4755
+
4756
+
nums.forEach(num=> {
4757
+
if (num) count +=1
4758
+
})
4759
+
4760
+
console.log(count)
4761
+
```
4762
+
4763
+
- A: 1
4764
+
- B: 2
4765
+
- C: 3
4766
+
- D: 4
4767
+
4768
+
<details><summary><b>Answer</b></summary>
4769
+
<p>
4770
+
4771
+
#### Answer: C
4772
+
4773
+
The `if` condition within the `forEach` loop checks whether the value of `num` is truthy or falsy. Since the first number in the `nums` array is `0`, a falsy value, the `if` statement's code block won't be executed. `count` only gets incremented for the other 3 numbers in the `nums` array, `1`, `2` and `3`. Since `count` gets incremented by `1` 3 times, the value of `count` is `3`.
4774
+
4775
+
</p>
4776
+
</details>
4777
+
4778
+
---
4779
+
4780
+
###### 147. What's the output?
4781
+
4782
+
```javascript
4783
+
functiongetFruit(fruits) {
4784
+
console.log(fruits?.[1]?.[1])
4785
+
}
4786
+
4787
+
getFruit([['🍊', '🍌'], ['🍍']])
4788
+
getFruit()
4789
+
getFruit([['🍍'], ['🍊', '🍌']])
4790
+
```
4791
+
4792
+
- A: `null`, `undefined`, 🍌
4793
+
- B: `[]`, `null`, 🍌
4794
+
- C: `[]`, `[]`, 🍌
4795
+
- D: `undefined`, `undefined`, 🍌
4796
+
4797
+
<details><summary><b>Answer</b></summary>
4798
+
<p>
4799
+
4800
+
#### Answer: D
4801
+
4802
+
The `?` allows us to optionally access deeper nested properties within objects. We're trying to log the item on index `1` within the subarray that's on index `1` of the `fruits` array. If the subarray on index `1` in the `fruits` array doesn't exist, it'll simply return `undefined`. If the subarray on index `1` in the `fruits` array exists, but this subarray doesn't have an item on its `1` index, it'll also return `undefined`.
4803
+
4804
+
First, we're trying to log the second item in the `['🍍']` subarray of `[['🍊', '🍌'], ['🍍']]]`. This subarray only contains one item, which means there is no item on index `1`, and returns `undefined`.
4805
+
4806
+
Then, we're invoking the `getFruits` function without passing a value as an argument, which means that `fruits` has a value of `undefined` by default. Since we're conditionally chaining the item on index `1` of`fruits`, it returns `undefined` since this item on index `1` does not exist.
4807
+
4808
+
Lastly, we're trying to log the second item in the `['🍊', '🍌']` subarray of `['🍍'], ['🍊', '🍌']`. The item on index `1` within this subarray is `🍌`, which gets logged.
4809
+
4810
+
</p>
4811
+
</details>
4812
+
4813
+
---
4814
+
4815
+
###### 148. What's the output?
4816
+
4817
+
```javascript
4818
+
classCalc {
4819
+
constructor() {
4820
+
this.count=0
4821
+
}
4822
+
4823
+
increase() {
4824
+
this.count++
4825
+
}
4826
+
}
4827
+
4828
+
constcalc=newCalc()
4829
+
newCalc().increase()
4830
+
4831
+
console.log(calc.count)
4832
+
```
4833
+
4834
+
- A: `0`
4835
+
- B: `1`
4836
+
- C: `undefined`
4837
+
- D: `ReferenceError`
4838
+
4839
+
<details><summary><b>Answer</b></summary>
4840
+
<p>
4841
+
4842
+
#### Answer: A
4843
+
4844
+
We set the variable `calc` equal to a new instance of the `Calc` class. Then, we instantiate a new instance of `Calc`, and invoke the `increase` method on this instance. Since the count property is within the constructor of the `Calc` class, the count property is not shared on the prototype of `Calc`. This means that the value of count has not been updated for the instance calc points to, count is still `0`.
The `updateUser` function updates the values of the `email` and `password` properties on user, if their values are passed to the function, after which the function returns the `user` object. The returned value of the `updateUser` function is the `user` object, which means that the value of updatedUser is a reference to the same `user` object that `user` points to. `updatedUser === user` equals `true`.
4887
+
4888
+
</p>
4889
+
</details>
4890
+
4891
+
---
4892
+
4893
+
###### 150. What's the output?
4894
+
4895
+
```javascript
4896
+
constfruit= ['🍌', '🍊', '🍎']
4897
+
4898
+
fruit.slice(0, 1)
4899
+
fruit.splice(0, 1)
4900
+
fruit.unshift('🍇')
4901
+
```
4902
+
4903
+
- A: `['🍌', '🍊', '🍎']`
4904
+
- B: `['🍊', '🍎']`
4905
+
- C: `['🍇', '🍊', '🍎']`
4906
+
- D: `['🍇', '🍌', '🍊', '🍎']`
4907
+
4908
+
<details><summary><b>Answer</b></summary>
4909
+
<p>
4910
+
4911
+
#### Answer: C
4912
+
4913
+
First, we invoke the `slice` method on the fruit array. The slice method does not modify the original array, but returns the value that it sliced off the array: the banana emoji.
4914
+
Then, we invoke the `splice` method on the fruit array. The splice method does modify the original array, which means that the fruit array now consists of `['🍊', '🍎']`.
4915
+
At last, we invoke the `unshift` method on the `fruit` array, which modifies the original array by adding the provided value, ‘🍇’ in this case, as the first element in the array. The fruit array now consists of `['🍇', '🍊', '🍎']`.
Copy file name to clipboardExpand all lines: en-EN/README.md
+171Lines changed: 171 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4745,3 +4745,174 @@ Objects aren't iterable by default. An iterable is an iterable if the iterator p
4745
4745
</p>
4746
4746
</details>
4747
4747
4748
+
-----
4749
+
4750
+
###### 146. What's the output?
4751
+
4752
+
```javascript
4753
+
letcount=0;
4754
+
constnums= [0, 1, 2, 3];
4755
+
4756
+
nums.forEach(num=> {
4757
+
if (num) count +=1
4758
+
})
4759
+
4760
+
console.log(count)
4761
+
```
4762
+
4763
+
- A: 1
4764
+
- B: 2
4765
+
- C: 3
4766
+
- D: 4
4767
+
4768
+
<details><summary><b>Answer</b></summary>
4769
+
<p>
4770
+
4771
+
#### Answer: C
4772
+
4773
+
The `if` condition within the `forEach` loop checks whether the value of `num` is truthy or falsy. Since the first number in the `nums` array is `0`, a falsy value, the `if` statement's code block won't be executed. `count` only gets incremented for the other 3 numbers in the `nums` array, `1`, `2` and `3`. Since `count` gets incremented by `1` 3 times, the value of `count` is `3`.
4774
+
4775
+
</p>
4776
+
</details>
4777
+
4778
+
---
4779
+
4780
+
###### 147. What's the output?
4781
+
4782
+
```javascript
4783
+
functiongetFruit(fruits) {
4784
+
console.log(fruits?.[1]?.[1])
4785
+
}
4786
+
4787
+
getFruit([['🍊', '🍌'], ['🍍']])
4788
+
getFruit()
4789
+
getFruit([['🍍'], ['🍊', '🍌']])
4790
+
```
4791
+
4792
+
- A: `null`, `undefined`, 🍌
4793
+
- B: `[]`, `null`, 🍌
4794
+
- C: `[]`, `[]`, 🍌
4795
+
- D: `undefined`, `undefined`, 🍌
4796
+
4797
+
<details><summary><b>Answer</b></summary>
4798
+
<p>
4799
+
4800
+
#### Answer: D
4801
+
4802
+
The `?` allows us to optionally access deeper nested properties within objects. We're trying to log the item on index `1` within the subarray that's on index `1` of the `fruits` array. If the subarray on index `1` in the `fruits` array doesn't exist, it'll simply return `undefined`. If the subarray on index `1` in the `fruits` array exists, but this subarray doesn't have an item on its `1` index, it'll also return `undefined`.
4803
+
4804
+
First, we're trying to log the second item in the `['🍍']` subarray of `[['🍊', '🍌'], ['🍍']]]`. This subarray only contains one item, which means there is no item on index `1`, and returns `undefined`.
4805
+
4806
+
Then, we're invoking the `getFruits` function without passing a value as an argument, which means that `fruits` has a value of `undefined` by default. Since we're conditionally chaining the item on index `1` of`fruits`, it returns `undefined` since this item on index `1` does not exist.
4807
+
4808
+
Lastly, we're trying to log the second item in the `['🍊', '🍌']` subarray of `['🍍'], ['🍊', '🍌']`. The item on index `1` within this subarray is `🍌`, which gets logged.
4809
+
4810
+
</p>
4811
+
</details>
4812
+
4813
+
---
4814
+
4815
+
###### 148. What's the output?
4816
+
4817
+
```javascript
4818
+
classCalc {
4819
+
constructor() {
4820
+
this.count=0
4821
+
}
4822
+
4823
+
increase() {
4824
+
this.count++
4825
+
}
4826
+
}
4827
+
4828
+
constcalc=newCalc()
4829
+
newCalc().increase()
4830
+
4831
+
console.log(calc.count)
4832
+
```
4833
+
4834
+
- A: `0`
4835
+
- B: `1`
4836
+
- C: `undefined`
4837
+
- D: `ReferenceError`
4838
+
4839
+
<details><summary><b>Answer</b></summary>
4840
+
<p>
4841
+
4842
+
#### Answer: A
4843
+
4844
+
We set the variable `calc` equal to a new instance of the `Calc` class. Then, we instantiate a new instance of `Calc`, and invoke the `increase` method on this instance. Since the count property is within the constructor of the `Calc` class, the count property is not shared on the prototype of `Calc`. This means that the value of count has not been updated for the instance calc points to, count is still `0`.
The `updateUser` function updates the values of the `email` and `password` properties on user, if their values are passed to the function, after which the function returns the `user` object. The returned value of the `updateUser` function is the `user` object, which means that the value of updatedUser is a reference to the same `user` object that `user` points to. `updatedUser === user` equals `true`.
4887
+
4888
+
</p>
4889
+
</details>
4890
+
4891
+
---
4892
+
4893
+
###### 150. What's the output?
4894
+
4895
+
```javascript
4896
+
constfruit= ['🍌', '🍊', '🍎']
4897
+
4898
+
fruit.slice(0, 1)
4899
+
fruit.splice(0, 1)
4900
+
fruit.unshift('🍇')
4901
+
```
4902
+
4903
+
- A: `['🍌', '🍊', '🍎']`
4904
+
- B: `['🍊', '🍎']`
4905
+
- C: `['🍇', '🍊', '🍎']`
4906
+
- D: `['🍇', '🍌', '🍊', '🍎']`
4907
+
4908
+
<details><summary><b>Answer</b></summary>
4909
+
<p>
4910
+
4911
+
#### Answer: C
4912
+
4913
+
First, we invoke the `slice` method on the fruit array. The slice method does not modify the original array, but returns the value that it sliced off the array: the banana emoji.
4914
+
Then, we invoke the `splice` method on the fruit array. The splice method does modify the original array, which means that the fruit array now consists of `['🍊', '🍎']`.
4915
+
At last, we invoke the `unshift` method on the `fruit` array, which modifies the original array by adding the provided value, ‘🍇’ in this case, as the first element in the array. The fruit array now consists of `['🍇', '🍊', '🍎']`.
0 commit comments