Q: 12
Refer to the code below:
for(let number =2 ; number <= 5 ; number += 1 ) {
// insert code statement here
}
The developer needs to insert a code statement in the location shown. The code
statement has these requirements:
1. Does require an import
2. Logs an error when the boolean statement evaluates to false
3. Works in both the browser and Node.js
Which meet the requirements?
Options
Discussion
Makes sense to go with D here.
console.assert is built in, works on both environments, and only logs when the condition fails, which matches what they're asking. That import requirement seems odd though. Anyone disagree?Option D
Had something like this in a mock exam, went with B.
D . People might pick A thinking assert needs import, but console.assert fits requirements for logging errors and cross-environment use.
Be respectful. No spam.