Refer to the code:
01 function execute() {
02 return new Promise((resolve, reject) => reject());
03 }
04 let promise = execute();
05
06 promise
07 .then(() => console.log('Resolved1'))
08 .then(() => console.log('Resolved2'))
09 .then(() => console.log('Resolved3'))
10 .catch(() => console.log('Rejected'))
11 .then(() => console.log('Resolved4'));
What is the result when the Promise in the execute function is rejected?
execute() returns a Promise that immediately calls reject().
So promise starts in a rejected state.
When a Promise is rejected and you chain .then() calls without rejection handlers, all those .then() callbacks are skipped until a .catch() is encountered:
promise
.then(...) // skipped
.then(...) // skipped
.then(...) // skipped
.catch(...) // executed
.then(...); // executed after catch
Execution:
.then(() => console.log('Resolved1')) is skipped.
.then(() => console.log('Resolved2')) is skipped.
.then(() => console.log('Resolved3')) is skipped.
.catch(() => console.log('Rejected')) runs and logs Rejected.
The .catch() returns a resolved Promise (no explicit return, so undefined), so the next .then() runs:
.then(() => console.log('Resolved4')) logs Resolved4.
Final output:
Rejected
Resolved4
This matches option D.
Refer to the following object:
const dog = {
firstName: 'Beau',
lastName: 'Boo',
get fullName() {
return this.firstName + ' ' + this.lastName;
}
};
How can a developer access the fullName property for dog?
The correct answer is A.
This object uses a getter:
get fullName() {
return this.firstName + ' ' + this.lastName;
}
A getter looks like a method when it is defined, but it is accessed like a normal property.
So the correct access syntax is:
dog.fullName
That returns:
'Beau Boo'
The important distinction is:
dog.fullName
not:
dog.fullName()
Because fullName is a getter property, not a regular function property.
Option B is incorrect because calling dog.fullName() tries to call the returned string as a function. Since 'Beau Boo' is not a function, that would cause a TypeError.
Option C is incorrect because there is no get object inside dog.
Option D is incorrect because there is no function object inside dog, and getters are not accessed that way.
Therefore, the verified answer is A.
Refer to the code below:
01 const myFunction = arr => {
02 return arr.reduce((result, current) => {
03 return result + current;
04 }, 10);
05 }
What is the output of this function when called with an empty array?
We call:
myFunction([]);
Inside:
arr.reduce((result, current) => {
return result + current;
}, 10);
Key points about Array.prototype.reduce:
Signature: array.reduce(callback, initialValue)
If initialValue is provided and the array is empty, reduce:
Does not call the callback at all.
Simply returns initialValue.
Here:
arr is [] (empty).
initialValue is 10.
So:
No iterations of the callback happen (no elements to process).
The return value is the initial value: 10.
So the actual output is:
myFunction([]) === 10;
Among the options:
A: 0 -- incorrect, because the initial value is 10, not 0.
B: Throws an error -- reduce throws only if the array is empty and there is no initialValue. Here we have an initial value, so no error.
C: NaN -- there is no arithmetic with undefined or invalid values; we just return 10.
D: Returns 5 -- the numeric value given is wrong; the correct value is 10.
Given the logic, the correct conceptual result is 10. The option text ''Returns 5'' is almost certainly a typo for ''Returns 10''. Since the letter that is intended to represent the correct behavior is D, we keep:
Answe r: D
Study Guide / Concept Reference (no links):
Array.prototype.reduce behavior with initialValue
Behavior of reduce on an empty array with and without initialValue
Return value when no iterations run
Given a value, which two options can a developer use to detect if the value is NaN?
Comprehensive and Detailed Explanation From Exact Extract JavaScript knowledge:
We already know NaN is special: it is not equal to itself.
Check each:
A . value === Number.NaN
Number.NaN is NaN.
NaN === NaN is always false.
This will never be true; cannot reliably detect NaN.
B . value == NaN
NaN == NaN is also always false.
Again, this never detects NaN.
C . isNaN(value)
Global isNaN converts its argument to a number and then checks if the result is NaN.
This can detect NaN, but it may also return true for non-number values that coerce to NaN, such as isNaN('foo').
Regardless, it is a standard way to detect if a value is ''NaN-like'' in JavaScript.
D . Object.is(value, NaN)
Object.is(NaN, NaN) returns true.
This is a strict way to detect a value that is exactly NaN (no coercion).
Therefore, among the given choices, the two viable ways to detect NaN are:
isNaN(value)
Object.is(value, NaN)
________________________________________
Refer to the code below:
01 x = 3.14;
02
03 function myFunction() {
04 'use strict';
05 y = x;
06 }
07
08 z = x;
09 myFunction();
Considering the implications of 'use strict' on line 04, which three statements describe the execution of the code?
Comprehensive and Detailed Explanation From Exact Extract JavaScript knowledge:
Behavior of non-strict global code
The script does not begin with a 'use strict' directive at the top level, so the global code (outside any function) runs in non-strict (sloppy) mode.
Line 01: x = 3.14;
In non-strict mode, assigning to an undeclared identifier (no var, let, or const) creates an implicit global variable. So after line 01, x exists and equals 3.14.
Line 08: z = x;
This also runs in non-strict mode. Since x is already defined (from line 01), z is set to 3.14. Therefore, statement B is correct: z is equal to 3.14.
Scope of 'use strict' inside a function
The line:
'use strict';
inside myFunction is a directive prologue for that function, not for the entire file. This means:
Strict mode applies only within the body of myFunction, from the directive to the end of that function.
It does not retroactively affect code before the function or code outside of it.
Therefore:
Statement A is incorrect: 'use strict' is not ''hoisted'' to affect the whole file. It only affects the function body.
Statement C is incorrect: strict mode does not apply from line 04 to the end of the file; it only applies within myFunction, not to global lines like 01, 08, or 09.
Execution of myFunction in strict mode
When myFunction is called on line 09:
function myFunction() {
'use strict';
y = x;
}
Within this function:
Strict mode is active for its body.
In strict mode, assigning to an undeclared variable (like y here) is not allowed and results in a ReferenceError at runtime.
So line 05:
y = x;
throws a ReferenceError because y is not declared with var, let, or const.
Therefore, statement E is correct: line 05 throws an error.
Why statement D is considered correct
Statement D says:
'use strict' has an effect only on line 05.
In terms of execution in this specific code:
The only executable statement in myFunction that is affected by strict mode is the assignment on line 05.
The directive itself on line 04 is not a ''normal'' runtime operation; it is a directive that sets the mode.
There are no other statements inside the function that behave differently under strict mode; only the line that assigns to the undeclared variable shows a strict-mode effect.
So, describing the practical execution behavior of this snippet, strict mode manifests its effect only on line 05, making statement D correct in this context.
Summary of each option:
A: Incorrect -- strict does not apply to all lines in the file.
B: Correct -- z becomes 3.14 in non-strict global code.
C: Incorrect -- strict does not affect code outside the function.
D: Correct -- in this code, the only behavioral effect of strict mode is on line 05.
E: Correct -- line 05 throws a ReferenceError due to assignment to undeclared y under strict mode.
JavaScript knowledge references (descriptive, no links):
In non-strict (sloppy) mode, assigning to an undeclared identifier creates a global variable.
'use strict' inside a function body enables strict mode for that function only.
In strict mode, assigning to an undeclared variable results in a ReferenceError.
Directive prologues ('use strict') affect only their containing function or script, not other scopes.
==================================================
Amanda Cooper
7 days agoAmy Thomas
9 days agoDavid Jackson
1 month agoKaren Jones
1 month agoCharles Carter
2 months agoHeather Bell
3 months agoBrenda Clark
2 months agoDeborah Mitchell
2 months agoJeffrey Bailey
2 months agoRobert Anderson
3 months agoGerald Ramirez
2 months agoMalcom
3 months agoZoila
3 months agoMicaela
4 months agoKendra
4 months agoPhyliss
4 months agoLeandro
4 months agoHelga
5 months agoBrent
5 months ago