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:

Edwin
1 months ago
Someone should tell the exam writers that their code needs a little more 'set' and a little less 'time-out'.
upvoted 0 times
...
Mila
1 months ago
I bet the exam writers were chuckling to themselves when they came up with this one. 'Let's see if they can keep up with our asynchronous antics!'
upvoted 0 times
...
Dante
1 months ago
This question is a real head-scratcher! I'm going to go with B) 0 1 2 3 because it just makes the most sense to me. But who knows, maybe the exam writers are trying to trick us with this one.
upvoted 0 times
...
Galen
1 months ago
I'm confused. Shouldn't the answer be C) 0 1 1 2? The first logCounter() call logs 0, the setTimeout call logs 1, and the setInterval call increments Counter and logs the new value, but the last log statement should be 2, not 3.
upvoted 0 times
Brande
2 days ago
B) 0 1 2 3
upvoted 0 times
...
Leonida
6 days ago
No, that's not correct. The first logCounter() call logs 0, the setTimeout call logs 0 again, and the setInterval call increments Counter and logs the new value.
upvoted 0 times
...
Patria
16 days ago
A) 0 0 1 2
upvoted 0 times
...
...
Kami
2 months 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
Truman
2 days ago
I agree with D) 0 1 2 2. The setTimeout call logs the Counter after the interval.
upvoted 0 times
...
Thora
17 days ago
I'm going with D) 0 1 2 2. The setInterval call increments Counter and logs the new value.
upvoted 0 times
...
Dewitt
27 days ago
I believe it's B) 0 1 2 3. The Counter is incremented before it is logged.
upvoted 0 times
...
Golda
1 months ago
I think it's A) 0 0 1 2. The Counter is logged before it is incremented.
upvoted 0 times
...
...
Michel
2 months 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
2 months 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
Margret
29 days ago
Finally, the setInterval call increments Counter and logs the new value every 1 second.
upvoted 0 times
...
Alex
1 months ago
Then the setTimeout call logs 0 after 1.1 seconds.
upvoted 0 times
...
Tabetha
1 months ago
Yes, that's correct. The first log statement logs 0.
upvoted 0 times
...
Torie
1 months ago
I think the answer is B) 0 1 2 3.
upvoted 0 times
...
...
Matthew
2 months 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
2 months 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