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
+15-15
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
I post daily multiple choice JavaScript questions on my [Instagram](https://www.instagram.com/theavocoder), which I'll also post here!
4
4
5
-
From basic to advanced: test how well you know JavaScript, refresh your knowledge a bit, or prepare for your coding interview! :muscle::rocket:
5
+
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 weekly with new questions.
6
6
7
7
The answers are in the collapsed sections below the questions, simply click on them to expand it. Good luck :heart:
8
8
@@ -160,7 +160,7 @@ JavaScript interprets (or unboxes) statements. When we use bracket notation, it
160
160
161
161
`mouse[bird.size]`: First it evaluates `bird.size`, which is `"small"`. `mouse["small"]` returns `true`
162
162
163
-
However, with dot notation. this doesn't happen. `mouse` does not have a key called `bird`, which means that `mouse.bird` is `undefined`. Then, we ask for the `size` using dot notation: `mouse.bird.size`. Since `mouse.bird` is `undefinfed`, we're actually asking `undefined.size`. This isn't valid, and will throw an error similar to `Cannot read property "size" of undefined`.
163
+
However, with dot notation, this doesn't happen. `mouse` does not have a key called `bird`, which means that `mouse.bird` is `undefined`. Then, we ask for the `size` using dot notation: `mouse.bird.size`. Since `mouse.bird` is `undefined`, we're actually asking `undefined.size`. This isn't valid, and will throw an error similar to `Cannot read property "size" of undefined`.
You can't add properties to a constructor like you can with regular objects. If you want to add a feature to all object at once, you have to use the prototype instead. So in this case,
355
+
You can't add properties to a constructor like you can with regular objects. If you want to add a feature to all objects at once, you have to use the prototype instead. So in this case,
356
356
357
357
```javascript
358
358
Person.prototype.getFullName=function() {
@@ -392,7 +392,7 @@ console.log(sarah);
392
392
393
393
#### Answer: A
394
394
395
-
For `sarah`, we didn't use the `new` keyword.When using `new`, it refers to the new empty object we create. However, if you don't add `new` it refers to the **global object**!
395
+
For `sarah`, we didn't use the `new` keyword.When using `new`, it refers to the new empty object we create. However, if you don't add `new` it refers to the **global object**!
396
396
397
397
We said that `this.firstName` equals `"Sarah"` and `this.lastName` equals `"Smith"`. What we actually did, is defining `global.firstName = 'Sarah'` and `global.lastName = 'Smith'`. `sarah` itself is left `undefined`.
398
398
@@ -519,9 +519,9 @@ const age = 21;
519
519
getPersonInfo`${person} is ${age} years old`;
520
520
```
521
521
522
-
- A: `Lydia``21``["", "is", "years old"]`
523
-
- B: `["", "is", "years old"]``Lydia``21`
524
-
- C: `Lydia``["", "is", "years old"]``21`
522
+
- A: `"Lydia"``21``["", " is ", "years old"]`
523
+
- B: `["", " is ", "years old"]``"Lydia"``21`
524
+
- C: `"Lydia"``["", " is ", "years old"]``21`
525
525
526
526
<details><summary><b>Answer</b></summary>
527
527
<p>
@@ -591,7 +591,7 @@ getAge(21);
591
591
592
592
#### Answer: C
593
593
594
-
The spread operator (`...args`.) retrusn an array with arguments. An array is an object, so `typeof args` returns `"object"`
594
+
The spread operator (`...args`.) returns an array with arguments. An array is an object, so `typeof args` returns `"object"`
595
595
596
596
</p>
597
597
</details>
@@ -620,7 +620,7 @@ getAge();
620
620
621
621
#### Answer: C
622
622
623
-
With `"use strict"`, you can make sure that you don't accidentally declare global variables. We never declared the variable `age`, and since we use `"use strict"`, it will throw a reference error. It we didn't use `"use strict"`, it would have worked, since the property `age` would have gotten added to the global object.
623
+
With `"use strict"`, you can make sure that you don't accidentally declare global variables. We never declared the variable `age`, and since we use `"use strict"`, it will throw a reference error. If we didn't use `"use strict"`, it would have worked, since the property `age` would have gotten added to the global object.
- C: When the uses closes the entire browser, not only the tab.
661
+
- C: When the user closes the entire browser, not only the tab.
662
662
- D: When the user shuts off their computer.
663
663
664
664
<details><summary><b>Answer</b></summary>
@@ -725,7 +725,7 @@ set.has(1);
725
725
726
726
#### Answer: C
727
727
728
-
All object keys (excluding Symbols) are strings under the hood, even if you don't type it youself as a string. This is why `obj.hasOwnProperty('1')` also returns true.
728
+
All object keys (excluding Symbols) are strings under the hood, even if you don't type it yourself as a string. This is why `obj.hasOwnProperty('1')` also returns true.
729
729
730
730
It doesn't work that way for a set. There is no `'1'` in our set: `set.has('1')` returns `false`. It has the numeric type `1`, `set.has(1)` returns `true`.
731
731
@@ -891,7 +891,7 @@ We have a `setTimeout` function and invoked it first. Yet, it was logged last.
891
891
892
892
This is because in browsers, we don't just have the runtime engine, we also have something called a `WebAPI`. The `WebAPI` gives us the `setTimeout` function to start with, and for example the DOM.
893
893
894
-
After the _callback_ is pushed to the WebAPI,the `setTimeout` function itself (but not the callback!) is popped off the stack.
894
+
After the _callback_ is pushed to the WebAPI,the `setTimeout` function itself (but not the callback!) is popped off the stack.
This is where an event loop starts to work. An **event loop** looks looks at the stack and task queue. If the stack is empty, it takes the first thing on the queue and pushes it onto the stack.
910
+
This is where an event loop starts to work. An **event loop** looks at the stack and task queue. If the stack is empty, it takes the first thing on the queue and pushes it onto the stack.
0 commit comments