
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are the best practices to be followed while using JavaScript?
The following are the best practices to be followed while using JavaScript −
End switch with default
Yes, it is a good practice to end switch with defaults. Always end it with defaults.
Create and use Varibles
In JavaScript, only create variables, which you will use and save values. Use the following and avoid unnecessary lines of code and variable declaration −
document.write(num.copyWithin(2,0));
Avoid the usage of with
The with keyword do not have a good impact on JavaScript speed. Avoid using it in your code.
Faster Looping
While using a loop, keep the assignment outside the loop. This would tun the loop faster −
var i; // assignment outside the loop var j = arr.length; for (i = 0; i < j; i++) { // code }
Avoid using Eval()
The usage of eval() function in JavaScript can lead to security issues.
Declaration always on top
It is a good practice to place all the JavaScript declarations at the top −
- Gives a single place to check for all the variables.
- Helps in avoiding global variables
- Re-declarations are avoided.
- The code is easy to read for others as well.
- Related Questions & Answers
- Explain JavaScript eval() function what are the rules to be followed while using it.
- What are the rules to be followed while using varargs in java?
- What are the guide lines to be followed while using wildcards in Java?
- What are the best practices to keep in mind while using packages in Java?
- What are the best practices for function overloading in JavaScript?
- What are the best practices for using loops in Python?
- What are the best practices to organize Python modules?
- What are the rules to be followed while making a variable static and final?
- What are the best practices for using if statements in Python?
- What are best practices to define Python classes?
- What are Python coding standards/best practices?
- What are the rules to be followed while working with a switch statement in java?
- What are the best practices to improve jQuery selector performance?
- What are the rules to be followed for Object Definitions in JavaScript?
- What are the best practices for committing in Git?
Advertisements