CRT-600 practice question 4 of 30

Refer to the code below: Const resolveAfterMilliseconds = (ms) => Promise.resolve ( setTimeout (( => console.log(ms), ms )); Const aPromise = await resolveAfterMilliseconds(500); Const bPromise = await resolveAfterMilliseconds(500); Await aPromise, wait bPromise; What is the result of running line 05?

Full set: 223 questions
Answer options
A: aPromise and bPromise run sequentially.
B: Neither aPromise or bPromise runs. Correct answer
C: aPromise and bPromise run in parallel.
D: Only aPromise runs.
Correct Answer:
B. Neither aPromise or bPromise runs.
Explanation

The provided code will fail to execute due to multiple fatal syntax errors on line 05: Await aPromise, wait bPromise;. First, the await operator must be in all lowercase. Second, wait is not a valid keyword or operator in JavaScript. These issues will cause the JavaScript engine to throw a SyntaxError during the parsing phase, which occurs before any code is executed. Consequently, the asynchronous functions on the preceding lines will not be invoked, and neither promise will run.

Why Incorrect

A. The await on lines 03 and 04 would imply sequential execution, but the fatal syntax error on line 05 prevents the script from running at all.
C. Parallel execution is not implemented. This would require initiating both promises before using await, which is contrary to the code's structure.
D. The script will fail entirely due to the syntax error. It is not a runtime error that would allow the first promise to run and then fail on the second.

References

1. ECMAScript® 2023 Language Specification (ECMA-262

14th edition):

Section 13.9.1

Static Semantics: Early Errors: The specification details that await is a keyword and is context-dependent (only valid within an async function). The use of an undefined identifier like wait and the incorrect capitalization Await constitute syntax errors that are detected before execution.

Annex B

Additional ECMAScript Features for Web Browsers: This section and the main body confirm that wait is not a reserved keyword or valid operator in any context.

2. MDN Web Docs (Mozilla):

await operator documentation: This official resource explicitly states the syntax is [rv] = await expression;. The code Await aPromise

wait bPromise; violates this syntax. The documentation confirms await is a reserved keyword only within async functions and must be lowercase. (Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await)

JavaScript lexical grammar: The list of keywords and reserved words does not include wait. Using an undefined identifier in this context results in a SyntaxError or ReferenceError

but given the structure

it's a parsing-time SyntaxError. (Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexicalgrammar#keywords)

Scroll to Top