Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Salesforce Exam Javascript Developer I Topic 9 Question 64 Discussion

Actual exam question for Salesforce's Javascript Developer I exam
Question #: 64
Topic #: 9
[All Javascript Developer I Questions]

Given the following code:

Counter = 0;

const logCounter = () => {

console.log(counter);

);

logCounter();

setTimeout(logCOunter, 1100);

setInterval(() => {

Counter++

logCounter();

}, 1000);

What is logged by the first four log statements?

Show Suggested Answer Hide Answer
Suggested Answer: B

Contribute your Thoughts:

Kami
3 days ago
I'm going with D) 0 1 2 2. The setInterval call increments Counter and logs the new value, but the last log statement should be 2 since the interval is 1 second and the setTimeout is 1.1 seconds.
upvoted 0 times
...
Michel
12 days ago
That's an interesting point, Matthew. I can see how that could be the case. Let's see what others think.
upvoted 0 times
...
Pura
15 days ago
I think the answer is B) 0 1 2 3. The code sets the Counter variable to 0, and then the first logCounter() call logs 0. The setTimeout call logs 0 after 1.1 seconds, and the setInterval call increments Counter and logs the new value every 1 second, so the output should be 0 1 2 3.
upvoted 0 times
...
Matthew
16 days ago
I disagree, I believe the answer is C) 0 1 1 2 because the logCounter function is called twice before the counter is incremented.
upvoted 0 times
...
Michel
24 days ago
I think the answer is B) 0 1 2 3 because the counter starts at 0 and then increments by 1 each time it is logged.
upvoted 0 times
...

Save Cancel
az-700  pass4success  az-104  200-301  200-201  cissp  350-401  350-201  350-501  350-601  350-801  350-901  az-720  az-305  pl-300  

Warning: Cannot modify header information - headers already sent by (output started at /pass.php:70) in /pass.php on line 77