Skip to content
Advertisement

Variable ‘value’ is used before being assigned

My code:

JavaScript

And got this:

JavaScript

I found this very odd, as I had seen other similar problems that either used a callback or a Promise or some other asynchronous method, while I used just a synchronous for loop.

———————————- Some update ————————

JavaScript

Advertisement

Answer

Use the non-null assertion operator to ensure that “its operand is non-null and non-undefined in contexts where the type checker is unable to conclude that fact.”

JavaScript

Result

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement