Javascript is powerful language, and is used more and more outside of web browsers. You can even make full-fledged video games with the Unity engine in Javascript!
creating functions in javascript not only make the code look cleaner, but they also significantly shorten the code and make it easier to add to later on. It is a good practice to start using in your code