The generally accepted mindset is to ignore security in client-side scripts (JS), and implement it entirely in server-side scripts (e.g. PHP). This is because the user is able to interface with your server in any which way they like.
For example, making sure that your form meets the requirements you have set by testing them with a JavaScript script it useless, because the user can just write their own form and submit it to your server. Alternatively, instead of writing their own form, they could load up your page and execute any arbitrary JavaScript code they like.
Quite simply, the user is able to alter anything you write in JavaScript. This is not the case server-side and thus we implement security features. You need only worry about your client-side scripts working.
With that said, there are certain inputs that might break your script depending on what you are doing with said input. For example, if you are putting the string through an `eval` call then the user might inject some code. Similarly if you are generating URLs the user might provide unexpected content to alter the URL in an undesirable way.
This is why we have the escape functions `escape`, `encodeURI` and `encodeURIComponent`.
Hope that helps
