JavaScript is a terrible language, so this isn’t really your fault.
I would suggest reading this thread in its entirety.