Most web projects involve writing Javascript, these days it’s more popular than ever. It’s important to know the fundamentals of how to write good Javascript, even if you don’t become a JS Ninja. There are some simple guidelines you can follow to instantly upgrade your skills, and ensure clean, maintainable code. Before we dive into that, let’s look at some beginner mistakes. What Not To Do I’ve seen some horrible Javascript, I mean the type of thing you can’t un-see. I once saw a file with dozens of jQuery ready functions, one after another: jQuery(document).ready(function($) { $('.button').click(function() { alert('do something'); }); }); jQuery(document).ready(function($) { $('.another-button').click(function() { alert('do something else'); }); }); jQuery(document).ready(function($) { $('#another-button2').click(function() { alert('do something else'); }); }); jQuery(document).ready(function($) { $('#another-button3').click(function() { alert('do something else'); }); }); ...ad infinitum This is way too much repeated code, and will quickly become difficult to read and maintain. You should only have the document ready function
Share This

We are using cookies on our website

Please confirm, if you accept our tracking cookies. You can also decline the tracking, so you can continue to visit our website without any data sent to third party services.