If you have a counter set to 0 and call setCounter(prev => prev + 1) three times consecutively inside an event handler, what will be the value of the counter?

  • 1
  • 2
  • 3
  • 4
The value of the counter will be 3. Each call to setCounter(prev => prev + 1) increments the counter by 1 based on the previous value. Since this is done three times consecutively, the counter goes from 0 to 1, then 1 to 2, and finally 2 to 3.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *