JavaScript is a language which has a lot skeletons in its closet.
If you don't know exactly what you doing, it is going to end up in a wrong way, or in a way you had not anticipated.
There is a great website "JavaScript Garden" which will help through the pitfalls.
From the website:
"It gives advice to avoid common mistakes and subtle bugs,
as well as performance issues and bad practices,
that non-expert JavaScript programmers may encounter on
their endeavours into the depths of the language"
Go there now! : JavaScript Garden