What you're experiencing is a basic floating point rounding error.
We can't precisely represent 0.1 without some error due to the nature of binary numbers. WolframAlpha reports decimal 0.1 to equal binary ~0.00011001100110011... Notice how it can't be finitely represented in the binary number system? This means we have to decide on a cut off point at which to stop calculating this number otherwise we'd be here forever.
This introduces an error. And this error has accumulated as the code adds the numbers together which results in an incredibly small quantity added to the end of your sum. This ensures that the sum will never be EXACTLY 0.3, which is what the IF
test is looking for.
Some decimal numbers, however, can be represented accurately in binary such as dec 0.5 = bin 0.1 and dec 0.25 = bin 0.01.
We can demonstrate this similarly to your original code by using 0.5 = (0.25 + 0.25).
For further reading on this I recommend The Floating-Point Guide.
It provides a good overview of the concept of floating point numbers and how errors in calculation can arise. There is also a section on Javascript which demonstrates how to overcome the rounding errors you're experiencing.