Optimize your JavaScript and jQuery practices with essential guidelines that enhance code quality and maintainability. This collection covers best practices for coding standards, library usage, and effective debugging, ensuring that your scripts run efficiently and reliably across different environments.
For most of the cases, it quite rare to have problems when omitting semicolons, but there are a few scenarios where they are required to prevent syntax errors or resolve code ambiguities.
We all know that jQuery is very powerful and can do a lot of stuff, including style changes. However, this practice is bad.
Don't assume JavaScript is always enabled.
JavaScript should be used to enhance the overall user experience and not as a dependency.
$(#id)is a selector of jQuery. It gets the single element with the given id.jQuery is a fast and concise JavaScript Library that simplifies how you traverse HTML documents, handle events, perform animations, and add Ajax interactions to your web pages. jQuery is designed to change the way that you write JavaScript.
Comments are used to add extra information pertaining to your code. They not only make you understand your code when you look at it after a period of time, but it also help other people who might be working with you on the same project.
The Javascript command "eval" evaluates the content of a text string and then runs it as Javascript code. It's common to see it around, however "eval" is one of the most inefficient constructs that JavaScript has. There are always more efficient ways to code and get a direct reference.
Below are some of the best technically cool jQuery plug-ins. Use these as guidelines for building your jQuery plug-ins:
Below are some of the best visually cool jQuery plug-ins. Use these as guidelines for building your jQuery plug-ins:
TypeScript is the new flagship language from Microsoft that compiles into JavasScript.
- Use JavaScript if you’re writing page specific script
- Use jQuery to improve cross-browser support
- Use TypeScript if you’re writing re-usable client side library
Don't use CoffeeScript (language is too different from JavaSript)
The popup blockers in several browsers prevent JavaScript from being used to open windows without user interaction (e.g. clicking a link). You should use an anchor tag instead.
- Do you always use semicolons on your JS file?
- Do you avoid making changes to individual CSS styles using jQuery?
- Do you avoid relying on Javascript for crucial actions?
- Do you avoid using document.getElementById(id) and document.all(id) to get a single element, instead use selector $(#id)?
- Do you comment your JavaScript code?
- Do you know not to use the "eval" function?
- Do you know what are the best examples of technically cool jQuery plug-ins?
- Do you know what are the best examples of visually cool jQuery plug-ins?
- Do you know when to use TypeScript (vs JavaScript and CoffeeScript)?
- Do you know you should not open popup windows and use a javascript modal instead?
- Do you place scripts at the bottom of your page?
- Do you remove "Language" from your script tag?
- Do you separate JavaScript functionality (aka Unobtrusive JavaScript)?
- Do you treat JavaScript like a real language?
- Do you understand that with Angular you read and write to the model... never to the page? (aka Forget about jQuery)
- Do you know the best package manager for Node?
- Do you use Bundling and/or AMD
- Do you use jQuery instead of JavaScript?
- Do you optimise your JavaScript code with Lodash wisely and efficiently?
- Do you use lodash to perform your daily _.foreach?
- Do you use the .ready() function?
- Do you use the best JavaScript libraries?
- Do you use the best Web UI libraries?
- Tools - Do you know the best tools to debug JavaScript?
- Do you know how to link local dependency for npm?