25. What's the output?
const obj = { a: 'one', b: 'two', a: 'three' }; console.log(obj);
const obj = { a: 'one', b: 'two', a: 'three' }; console.log(obj);
Anonymous Poll
30%
A: { a: "one", b: "two" }
17%
B: { b: "two", a: "three" }
17%
C: { a: "three", b: "two" }
35%
D: SyntaxError
DevScrolls
25. What's the output?
const obj = { a: 'one', b: 'two', a: 'three' }; console.log(obj);
const obj = { a: 'one', b: 'two', a: 'three' }; console.log(obj);
Answer: C
If you have two keys with the same name, the key will be replaced. It will still be in its first position, but with the last specified value.
If you have two keys with the same name, the key will be replaced. It will still be in its first position, but with the last specified value.
26. The JavaScript global execution context creates two things for you: the global object, and the "this" keyword.
Anonymous Poll
55%
A: true
18%
B: false
27%
C: it depends
27. What's the output?
for (let i = 1; i < 5; i++) { if (i === 3) continue; console.log(i); }
for (let i = 1; i < 5; i++) { if (i === 3) continue; console.log(i); }
Anonymous Poll
16%
A: 1 2
42%
B: 1 2 3
39%
C: 1 2 4
3%
D: 1 3 4
28. What's the output?
A: "Just give Lydia pizza already!"
B: TypeError: not a function
C: SyntaxError
D: undefined
String.prototype.giveLydiaPizza = () => {
return 'Just give Lydia pizza already!'; };
const name = 'Lydia'; console.log(name.giveLydiaPizza())A: "Just give Lydia pizza already!"
B: TypeError: not a function
C: SyntaxError
D: undefined
DevScrolls
What's the output?
Answer: A
String is a built-in constructor, which we can add properties to. I just added a method to its prototype. Primitive strings are automatically converted into a string object, generated by the string prototype function. So, all strings (string objects) have access to that method!
String is a built-in constructor, which we can add properties to. I just added a method to its prototype. Primitive strings are automatically converted into a string object, generated by the string prototype function. So, all strings (string objects) have access to that method!
29. What's the output?
const a = {}; const b = { key: 'b' }; const c = { key: 'c' }; a[b] = 123; a[c] = 456; console.log(a[b]);
const a = {}; const b = { key: 'b' }; const c = { key: 'c' }; a[b] = 123; a[c] = 456; console.log(a[b]);
Anonymous Poll
33%
A: 123
22%
B: 456
26%
C: undefined
19%
D: ReferenceError
DevScrolls
29. What's the output?
const a = {}; const b = { key: 'b' }; const c = { key: 'c' }; a[b] = 123; a[c] = 456; console.log(a[b]);
const a = {}; const b = { key: 'b' }; const c = { key: 'c' }; a[b] = 123; a[c] = 456; console.log(a[b]);
Answer: B
Object keys are automatically converted into strings. We are trying to set an object as a key to object a, with the value of 123.
However, when we stringify an object, it becomes "[object Object]". So what we are saying here, is that a["[object Object]"] = 123. Then, we can try to do the same again. c is another object that we are implicitly stringifying. So then, a["[object Object]"] = 456.
Then, we log a[b], which is actually a["[object Object]"]. We just set that to 456, so it returns 456.
Object keys are automatically converted into strings. We are trying to set an object as a key to object a, with the value of 123.
However, when we stringify an object, it becomes "[object Object]". So what we are saying here, is that a["[object Object]"] = 123. Then, we can try to do the same again. c is another object that we are implicitly stringifying. So then, a["[object Object]"] = 456.
Then, we log a[b], which is actually a["[object Object]"]. We just set that to 456, so it returns 456.
30. What's the output?
A: First Second Third
B: First Third Second
C: Second First Third
D: Second Third First
const foo = () => console.log('First');
const bar = () => setTimeout(() => console.log('Second')); const baz = () => console.log('Third');
bar();
foo();
baz();A: First Second Third
B: First Third Second
C: Second First Third
D: Second Third First
Answer: B
We have a setTimeout function and invoked it first. Yet, it was logged last.
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.
After the callback is pushed to the WebAPI, the setTimeout function itself (but not the callback!) is popped off the stack.

Now, foo gets invoked, and "First" is being logged.

foo is popped off the stack, and baz gets invoked. "Third" gets logged.

The WebAPI can't just add stuff to the stack whenever it's ready. Instead, it pushes the callback function to something called the queue.

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.

bar gets invoked, "Second" gets logged, and it's popped off the stack.
We have a setTimeout function and invoked it first. Yet, it was logged last.
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.
After the callback is pushed to the WebAPI, the setTimeout function itself (but not the callback!) is popped off the stack.

Now, foo gets invoked, and "First" is being logged.

foo is popped off the stack, and baz gets invoked. "Third" gets logged.

The WebAPI can't just add stuff to the stack whenever it's ready. Instead, it pushes the callback function to something called the queue.

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.

bar gets invoked, "Second" gets logged, and it's popped off the stack.
32. When you click the paragraph, what's the logged output?
A: p div
B: div p
C: p
D: div
<div onclick="console.log('div')"> <p onclick="console.log('p')"> Click here! </p> </div>A: p div
B: div p
C: p
D: div
DevScrolls
32. When you click the paragraph, what's the logged output? <div onclick="console.log('div')"> <p onclick="console.log('p')"> Click here! </p> </div> A: p div B: div p C: p D: div
Answer: A
If we click p, we see two logs: p and div. During event propagation, there are 3 phases: capturing, target, and bubbling. By default, event handlers are executed in the bubbling phase (unless you set useCapture to true). It goes from the deepest nested element outwards.
If we click p, we see two logs: p and div. During event propagation, there are 3 phases: capturing, target, and bubbling. By default, event handlers are executed in the bubbling phase (unless you set useCapture to true). It goes from the deepest nested element outwards.
33. What's the output?
} console.log(sayHi.call(person, 21)); console.log(sayHi.bind(person, 21));
A: undefined is 21 Lydia is 21
B: function function
C: Lydia is 21 Lydia is 21
D: Lydia is 21 function
const person = { name: 'Lydia' };
function sayHi(age) {
return ${this.name} is ${age}; } console.log(sayHi.call(person, 21)); console.log(sayHi.bind(person, 21));
A: undefined is 21 Lydia is 21
B: function function
C: Lydia is 21 Lydia is 21
D: Lydia is 21 function
DevScrolls
33. What's the output? const person = { name: 'Lydia' }; function sayHi(age) { return ${this.name} is ${age}; } console.log(sayHi.call(person, 21)); console.log(sayHi.bind(person, 21)); A: undefined is 21 Lydia is 21 B: function function C: Lydia is 21 Lydia…
Answer: D
With both, we can pass the object to which we want the this keyword to refer to. However, .call is also executed immediately!
.bind. returns a copy of the function, but with a bound context! It is not executed immediately.
With both, we can pass the object to which we want the this keyword to refer to. However, .call is also executed immediately!
.bind. returns a copy of the function, but with a bound context! It is not executed immediately.