-
Hi everyone, In the FundMe.test.js code below, (testing withdraw function) fundMeConnectedContract is declared const inside the for loop. Everytime when the loop iterates, fundMeConnectedContract get a new value as fundMe contract-abstraction gets connected to the next account. So, why declaring fundMeConnectedContract as const does not throw any error, if its value is changing? Is it because everytime when the loop re-iterates, the block structure inside for loop is a fresh one and has nothing to do with the previous iteration of the loop?? Otherwise, how a const inside a block can keep on getting new values? Any inputs please. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The variable fundMeConnectedContract is scoped inside the for loop, so re-running the loop re-declares it. |
Beta Was this translation helpful? Give feedback.
The variable fundMeConnectedContract is scoped inside the for loop, so re-running the loop re-declares it.
If you declare it outside the loop as const and then change values it should show an error of assigning to a constant variable.