1. Naming conventions
Naming conventions in Javascript are a set of guidelines used to name variables, functions,
classes, and other identifiers in a consistent and readable manner. Some common naming
conventions in Javascript are:
- CamelCase: This is a convention where the first word is in lowercase and the firstletter of the second word is capitalized, without using any underscores or spaces.
- For example: firstName, lastName, totalAmount.
- PascalCase: This convention is similar to CamelCase, but the first letter of the firstword is also capitalized. This convention is often used for class names andconstructor functions.
- For example: Customer, Order, Product.
- snake_case: This convention uses all lowercase letters and underscores to separatewords.
- For example: first_name, last_name, total_amount.
Use camelCase notation for naming variables, functions, and methods.
Use PascalCase notation for naming classes and constructors.
Some of the naming conventions are given below:
a) Meaningful and understandable variable names helps anyone to understand the
reason for using it.
b) Local variables should be named using camelCase lettering (e.g. localData) whereas
Global variables names should use PascalCase (e.g. GlobalData). Constant names
should be formed using uppercase letters only (e.g. CONSDATA).
c) It is better to avoid the use of digits in variable names.
d) The names of the function should be written in camel case
e) The name of the function must describe the reason for using the function clearly and
briefly.
Example:
- functionNamesLikeThis
- variableNamesLikeThis
- ClassNamesLikeThis
- EnumNamesLikeThis
- methodNamesLikeThis
- CONSTANT_VALUES_LIKE_THIS
- foo.namespaceNamesLikeThis.bar
- filenameslikethis.js.
f) Filenames should be all lowercase in order to avoid confusion on case-sensitive
platforms. Filenames should end in .js, and should contain no punctuation except for
underscore ( _ ).
2. Use strict mode
“use strict” mode is a way to enforce stricter parsing and error handling rules in your code.
When you use strict mode, certain actions in your code that would normally have been ignored or would have failed will now throw errors. This makes it easier to write “secure”
code, as it can prevent some common coding mistakes.
Some of the benefits of using strict mode are:
- Variables must be declared before they are used
- Duplicate parameter names are not allowed in function declarations or expressions
- Writing to a read-only property will cause a runtime error
- Octal numeric literals are not allowed
- With statements are not allowed
- Strict mode also disables certain features of JavaScript that are considered problematic or unnecessary.
- For example, with strict mode enabled, the with statement and the eval() function are disabled, as they can lead to unexpected behavior and security vulnerabilities.
To enable strict mode, simply add the statement “use strict” at the beginning of your code or function. This will enable strict mode for the entire file or function, respectively.
Use ‘use strict‘ at the beginning of your JavaScript files to enable strict mode. It helps to avoid common programming errors and promotes good coding practices.
3. Limited use of globals
Global variables are variables declared outside of a function, and they can be accessed and modified from any part of the code, which can make it difficult to track where the variable is being used and can lead to unexpected behaviour.
By limiting the use of global variables, code becomes more modular and easier to maintain, as the scope of the variable is restricted to the function where it is declared, and it cannot be modified from outside that function. This also helps to avoid naming conflicts, where two or more variables with the same name are declared in different parts of the code.
To limit the use of global variables, it is recommended to use function closures or modules to encapsulate code and declare variables within their own scope. This helps to ensure that the variable is only accessible within the scope of the function, and not from any other part of the code. Additionally, the use of the “let” and “const” keywords in modern versions of JavaScript can also help to limit the scope of variables and prevent the use of global variables. Use function scoping and closures to encapsulate your code.
Try to avoid non-const global variables. Avoid using global variables as they can be accessed and modified from anywhere in your code. Global variables and functions can be overwritten by other scripts.
4. Always Declare Local Variables
The purpose of ‘Always Declare Local Variables’ in JavaScript is to ensure that all variables used in a function or block are explicitly declared with the let, or const keyword. This helps prevent common errors that can occur when a variable is not declared, such as accidentally creating a global variable or referencing a variable that does not exist.
When a variable is not explicitly declared with let, or const, JavaScript will create a global variable with the same name in the global scope. This can lead to unexpected behavior and bugs in large code bases.
By enforcing the rule of always declaring local variables, JavaScript developers can write cleaner and more maintainable code that is less prone to errors and bugs. This is especially important in large code bases and team projects, where consistency and readability are crucial for efficient collaboration and maintenance. All variables used in a function should be declared as local variables. Local variables must be declared with the let keyword.
5. Use const and let
The purpose of using const and let instead of var in JavaScript is to provide better scoping and prevent accidental reassignment of variables.
const is used to declare a variable whose value is constant and cannot be reassigned. This makes the code more secure and helps prevent unintended changes to important values.
let is used to declare a variable with block scope. Unlike var, let is scoped to the block in which it is defined. This helps prevent naming collisions and unintended changes to variables.
Using const and let also helps in better code readability and maintenance. It makes it easier to understand the intent of the code and identify potential bugs.
6. Avoid eval
The eval() function in JavaScript allows dynamic execution of code, which can be a security risk if the code being executed comes from an untrusted source. The purpose of avoiding the use of eval() in JavaScript is to minimize this security risk.
When a string is passed to the eval() function, the code in the string is executed as if it were part of the current script. This means that any malicious code contained in the string can potentially access sensitive information or execute harmful actions on the user’s device.
In addition to the security risk, using eval() can also make the code harder to read and maintain, as it can be difficult to predict the outcome of dynamically executed code.
Therefore, it is recommended to avoid using eval() in JavaScript and instead use other ways to achieve the same functionality, such as using Function() constructor, which can also execute dynamic code but with more controlled access to the environment.
Avoid using eval as it can execute arbitrary code and can cause security issues.
7. Use braces
Using braces {} is considered a good practice when writing code blocks, such as for loops, if statements, functions, and so on. The purpose of using braces is to improve the code’s readability and to prevent potential issues with the scope of variables.
For example, consider the following code:
if (condition)
doSomething();
In this case, doSomething() will only be executed if condition is true. However, if someone later adds another line of code after the if statement, it may mistakenly be considered part of the if block, like this:
if (condition)
doSomething();
doSomethingElse();
In this case, doSomethingElse() will always be executed, regardless of whether condition is true or false. This mistake could have been avoided by using braces:
if (condition) {
doSomething();
doSomethingElse();
}
In this case, both doSomething() and doSomethingElse() will only be executed if condition is true. The use of braces makes the code’s intent clearer and helps prevent potential bugs.
Always use braces for if statements, loops, and functions, even if they contain only one statement. This helps to avoid errors and makes your code more readable.
8. Code formatting
Code formatting refers to the style and structure of the code, including indentation, spacing, and placement of brackets and braces. The purpose of code formatting in JavaScript is to make the code more readable and easier to understand for both developers and other stakeholders. Consistent and clear code formatting can help to reduce errors, improve collaboration among team members, and make maintenance and updates more efficient. It can also make the code easier to navigate and troubleshoot, particularly for larger or more complex projects. Additionally, following a common code formatting standard, such as the popular JavaScript Standard Style or Google JavaScript Style Guide, can help to ensure consistency and clarity across a team or organization’s codebase. This helps ensure that your code is easy to understand for other developers who may be working on the project.
Use consistent code formatting to make your code more readable. Use indentation, spacing, and line breaks to organize your code and make it easier to read.
a) Indentation
Proper indentation is very important to increase the readability of the code. For making the code readable, programmers should use white spaces and tabs properly.
Use a consistent number of spaces or tabs to indent each block of code. The most commonly used indentation size is 2 or 4 spaces. Some of the spacing conventions are given below:
i) There must be a space after giving a comma between two function arguments.
ii) Each nested block should be properly indented and spaced.
iii) Proper Indentation should be there at the beginning and at the end of each block in the program.
iv) All braces should start from a new line and the code following the end of braces also starts from a new line.
b) Line breaks
Break long lines of code into multiple lines to improve readability. Use line breaks to separate different sections of code, such as function declarations, if/else statements, or loops.
c) Vertical alignment
Align similar code blocks vertically to make it easier to read and understand the structure of your code.
For example, align the equal signs in a series of variable assignments, or the parameters in a list of function calls.
d) Structuring Code
With all of our code aligned at the left of the file (or unaligned), it’s not very easy to see the various levels of hierarchy we have. Keep the code in a hierarchical model.
define([], function () {
/**
* Function to show an alert
* @returns {void}
*/
function showMessage() {
let message = "Hello, Eric!";
alert(message);
}
return {
showMessage: showMessage,
};
});
Structuring code in JavaScript is essential to keep it organized, maintainable, and scalable. Here are some best practices to structure code in JavaScript
- Use modular design
- Break your code into smaller, independent functions and modules, and organize them in a logical manner. This makes it easier to understand how the code works, and makes it easier to maintain and update.
- Follow naming conventions
- Use descriptive, meaningful and consistent names for variables, functions, classes, and modules. Avoid using abbreviations or one-letter variable names that are difficult to understand. This practice helps to improve code readability and maintainability.
- Use comments
- Add comments to explain the purpose, functionality, and usage of functions, classes, and modules. Use comments to explain the code and its purpose.
- Comments should be concise and to the point. This practice helps to understand the code and its intent easily.
- Separate concerns
- Divide code into separate modules based on functionality, such as data access, user interface, business logic, and utilities. This approach helps to keep the code clean, easy to read, and maintainable.
- Use indentation
- Use consistent indentation to improve code readability and structure.
- Use whitespace
- Add whitespace to separate code blocks, statements, and operators.
- For example, add a space after commas and around operators. This practice helps to improve code readability and reduce errors.
- Keep lines short
- Keep lines of code short and avoid writing long statements that span multiple lines.
- Use consistent formatting
- Use consistent formatting for code blocks, such as braces, semicolons, and quotes. This approach helps to improve code consistency and reduce errors.
- Use of semicolon
- The semicolon (;) is used to mark the end of a statement. The semicolon is optional in most cases, as the JavaScript parser will automatically insert semicolons to end statements in certain situations. However, it is considered a best practice to include semicolons at the end of statements to avoid unexpected issues that can arise from relying on automatic semicolon insertion.
- Use linting tools
- Use linting tools such as ESLint, JSLint, or JSHint to enforce coding standards across the project, identify errors, and improve code quality.
9. Standard headers for different modules
For better understanding and maintenance of the code, the header of different modules should follow some standard format and information. The header format must contain below things that is being used in various companies:
- Name of the module
- Date of module creation
- Author’s employee code
- Modification history
- Synopsis of the module about what the module does
- Different functions supported in the module along with their input output parameters
- Follow JSDOC while writing comments
- Global variables accessed or modified by the module
/**
* @NApiVersion 2.1
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
/************************************************************************************************
* ABC Industries
*
* ${JIRA_CODE} : ${JIRA_TITLE}
*
* **********************************************************************************************
*
* Author: Jobin and Jismi IT Services
*
* Date Created : 01-August-2022
*
* Description : This script is for…
*
* REVISION HISTORY
*
* @version 1.0 ABC-5 : 01-August-2022 : Created the initial build by JJ0011
* @version 1.1 ABC-10 : 07-August 2022 : Updated the logic update for reference by JJ0013
*
*
***********************************************************************************************/
define([], function () {
....................................................
10. Code should be well documented
Use comments to explain your code and make it more understandable. Use descriptive names for your variables and functions to make your code self-documenting. Comments regarding the statements increase the understandability of the code.
Please note: If it isn’t documented, it doesn’t exist.
a) Proper Use of JSDOC tags
JSDoc is a documentation generation tool for JavaScript. It is important to follow best practices when using JSDoc to ensure that the documentation is accurate, consistent, and useful. Use JSDoc tags to document function parameters, return values, and any exceptions that may be thrown.
Check this to know more on JSDoc.
Here are some best practices for using JSDoc in JavaScript:
i. Use JSDoc comments for all functions and methods: JSDoc comments should be used for all functions and methods to provide documentation on their behavior and usage.
ii. Use descriptive names for parameters: The parameter names in the JSDoc comments should be descriptive and clearly indicate the purpose of the parameter.
iii. Use types in JSDoc comments: Use types to indicate the expected type of each parameter and the return value of the function or method.
iv. Use @param and @return tags: Use the @param and @return tags in JSDoc comments to document the parameters and return values of functions and methods.
v. Keep JSDoc comments up to date: It is important to keep JSDoc comments up to date with the latest changes to the code, to ensure that the documentation is accurate.Use JSDoc comments for classes and properties: Use JSDoc comments to document classes and their properties, including their types and default values.
vi. Use JSDoc comments for classes and properties: Use JSDoc comments to document classes and their properties, including their types and default values.
vii. Use @example and @see tags: Use the @example tag to provide code examples, and the @see tag to link to related documentation.
viii. Use a consistent style: Use a consistent style when writing JSDoc comments, including capitalization, punctuation, and spacing.
ix. Use JSDoc with linting tools: Use JSDoc with linting tools to ensure that the documentation is consistent with the code.
x. Use JSDoc with automated documentation tools: Use JSDoc with automated documentation tools to generate documentation from the code.
xi. For Example:
/**
* Function to show an alert
* @param {string} message - the message that needs to be alerted
* @returns {void}
*/
function showMessage(message) {
alert(message);
}
b) Document external dependencies
If your code depends on external libraries or APIs, document those dependencies in your code. This helps other developers understand the requirements for running your code.
c) Document external dependencies
If your code depends on external libraries or APIs, document those dependencies in your code. This helps other developers understand the requirements for running your code.
11. Avoid using a coding style that is too difficult to understand
Keep your code simple and easy to understand. Avoid using complicated syntax or advanced language features that may be difficult for other developers to follow. The complex code makes maintenance and debugging difficult and expensive.
12. Error return values and exception handling conventions
Always include error handling in your code to catch and handle any errors that may occur. You must handle every exception in your code in a principled way; the specific handling varies depending on the case.
Refer this for
- JavaScript error reference
- JavaScript Error Types
- Custom errors, extending Error
- How to create custom errors in JavaScript
Error and exception handling is an important aspect of writing robust and reliable code in JavaScript. Here are some best practices to follow:
a) Use try-catch blocks for exception handling
Wrap code that might throw an exception in a try block, and catch the exception in a
catch block. Use try-catch statements to catch exceptions and handle errors
gracefully. This helps prevent your program from crashing in case an exception is
thrown.
b) Return error objects
When a function encounters an error condition, it should return an error object. The
error object should contain information about the error, such as a message and error
code. This makes it easier to handle errors in the calling/invoking code.
c) Use custom error types
Define custom error types for specific types of errors in your application. This can
make it easier to handle and catch specific types of errors.
d) Use meaningful error messages
When throwing an error, make sure to use descriptive error messages that explain
what went wrong and provide hints for how to fix the problem.
e) Avoid throwing exceptions unnecessarily
Exceptions should only be thrown for exceptional situations. If an error can be
handled in a simpler way, it should be handled that way.
f) Use error-first callbacks
If using callbacks in your code, use error-first callbacks. This means that the first
argument of the callback is an error object, if there is one. This ensures that errors
can be handled in a consistent way across the codebase.
g) Always handle errors
Never ignore or suppress errors. Always handle them appropriately, whether by
logging them or taking some other action to alert the user or fix the problem. Even if
the error doesn’t crash the code, it should be logged or reported in some way.
h) Be consistent
Use consistent error handling throughout the codebase. This makes the code more
predictable and easier to maintain.
All functions that encounter an error condition should either
a) Return a 0/false or 1/true for simplifying the debugging.
b) Return error object
c) Return custom error types
d) Return a value in the data type that is expected from the function.
For example: If a function returns an array of numbers, then the catch statement can
return an empty array.
/**
* To know whether the transaction exists or not
* @param {string} transactionId - Can be either the transaction document number or internal id
* @returns {false|Object[]|[]}
*/
function pingSalesOrder(transactionId) {
try {
transactionId = transactionId?.toString()?.trim();
//Proceed only if transactionId is not empty
if (!transactionId) {
return false;
}
let filterArray = [];
//Add the filter for search using Internal ID only if transactionId data type is number
if (Number.isInteger(Number(transactionId))) {
filterArray = [
"OR",
["internalidnumber", "equalto", transactionId]
];
}
//Create the saved search object
const transactionSearchObj = search.create({
type: "salesorder",
filters: [
["type", "anyof", "SalesOrd"],
"AND",
["mainline", "is", "T"],
"AND",
[
["formulatext: {tranid}", "is", transactionId]
].concat(filterArray)
],
columns: [
search.createColumn({ name: "internalid", sort: search.Sort.DESC, label: "internalid" }),
search.createColumn({ name: "entity", label: "entity" }),
search.createColumn({ name: "tranid", label: "tranid" }),
]
});
let searchResultCount = transactionSearchObj.runPaged().count;
log.debug("pingSalesOrder result count", searchResultCount);
// Run the search and return the results.
const searchResults = transactionSearchObj.run().getRange({ start: 0, end: 1 });
if (searchResults && Uint8ClampedArray.isArray(searchResults) && searchResults.length > 0) {
return [{
"internalid": searchResults[0].getValue({ name: "internalid", label: "internalid" }),
"entity": searchResults[0].getValue({ name: "entity", label: "entity" }),
"tranid": searchResults[0].getValue({ name: "tranid", label: "tranid" }),
}]
}
return [];
} catch (err) {
log.error('error@pingSalesOrder', err);
return false;
}
}
13. Avoid using same identifier for multiple purposes
Each variable should be given a descriptive and meaningful name indicating the reason behind using it. This is not possible if an identifier is used for multiple purposes and thus it can lead to confusion to the reader. Moreover, it leads to more difficulty during future enhancements. The best practice to avoid using the same identifier for multiple purposes in JavaScript is to ensure that each identifier has a unique and consistent meaning throughout the codebase. This means that a variable, function, or object should have a name that accurately reflects its purpose and should only be used for that purpose.
a) Use descriptive names for identifiers such as variables, functions, and objects
Choose names that clearly describe the purpose of the identifier, so that it is easy to
understand what it represents and how it should be used. Avoid using generic or
ambiguous names such as “temp” or “data”. Instead, use descriptive and specific
names that clearly convey the purpose of the identifier, such as “userData” or
“totalAmount”.
b) Use separate identifiers for different purposes
Declare each identifier only once. Avoid using the same variable, function, or object
for multiple purposes within your code. This can lead to confusion and errors.
Instead, create separate identifiers for each distinct purpose once and use it
consistently throughout the code.
c) Keep scope in mind
Be aware of the scope of your identifiers and how they are used within your code.
Avoid using the same name for a variable or function in different scopes, as this can
lead to confusion and errors.
d) Use constants for fixed values
When working with fixed values that should not be changed, use constants (declared
with const) instead of variables. This will help prevent accidental changes to these
values later on in your code.
e) Use different naming conventions for different types of identifiers
Use different naming conventions for variables, functions, and objects.
For example,
you can use camelCase for variables and functions, and PascalCase for classes.
f) Document the purpose of each identifier
It is important to document the purpose of each identifier, especially if the codebase
is complex or if multiple developers are working on it. This can be done through
comments or by using a documentation tool such as JSDoc.
14. Log whenever required only
Use the logs properly and wherever required only. Delete or comment out the logs on the production/final version of the script. Logging is an important part of debugging and troubleshooting in JavaScript. However, logging too much can slow down the application and make it difficult to find the relevant information. Here are some best practices for logging in JavaScript:
a) Log only what is necessary
Before adding a log statement, consider whether it is necessary. Avoid logging
information that is not relevant to the current issue or feature
b) Use meaningful log messages
Log messages should be clear and informative, so that developers can quickly
understand what the message is communicating. Avoid using vague or cryptic
messages.
c) Use appropriate log levels
Different log levels (such as debug, info, warn, and error in browser –OR– debug,
audit, error, emergency in NetSuite) provide different levels of detail about the
application’s state. Use the appropriate log level for each message to ensure that the
log output is not cluttered with unnecessary information.
d) Be careful with sensitive data
Avoid logging sensitive data such as passwords, user details, or financial information.
If necessary, obfuscate or encrypt the data before logging.
e) Avoid logging in production
Logging can slow down the application and consume resources. Avoid logging in
production environments unless it is necessary for troubleshooting an issue.
15. Performance considerations
Consider performance when writing your code. Avoid unnecessary loops, function calls, and object creation. Use built-in JavaScript methods and functions whenever possible, as they are optimized for performance.
Performance considerations are essential when writing JavaScript code, and some of the best practices include:
- Minimize DOM Access
- DOM manipulation can be expensive, so it is important to minimize the number of times you access or modify the DOM.
- Use efficient data structures and algorithms
- The choice of data structures and algorithms can have a significant impact on the performance of your JavaScript code. Therefore, it is important to use efficient data structures and algorithms whenever possible.
- Optimize loops
- Looping through arrays or objects can be a performance bottleneck, so it is important to optimize loops by minimizing the number of iterations and avoiding unnecessary work inside the loop.
- Avoid excessive function calls
- Function calls in JavaScript can be expensive, so it is important to avoid excessive function calls whenever possible.
- Use asynchronous programming techniques
- Asynchronous programming techniques, such as callbacks, promises, and async/await, can help to avoid blocking the main thread and improve the performance of your JavaScript code.
- Minimize network requests
- Network requests can be expensive, so it is important to minimize the number of network requests and optimize their performance by using techniques such as caching and compressing data.
- Minimize the use of global variables
- Global variables can slow down your JavaScript code, so it is important to minimize their use and keep your variables as local as possible.
- Optimize resource loading
- Loading resources such as images, scripts, and stylesheets can impact the performance of your JavaScript code, so it is important to optimize their loading by using techniques such as lazy loading, preloading, and minification.
16. While writing functions
There are several best practices to keep in mind when writing functions in JavaScript:
- Function naming
- Function names should be descriptive and follow camelCase convention. The name should accurately reflect what the function does.
- Function parameters
- The number of parameters should be kept to a minimum. Parameters should be properly typed and named to convey their purpose.
- Function length
- Functions should be short and to the point. Ideally, functions should not exceed 30 lines of code. Lengthy functions are very difficult to understand. That’s why functions should be small enough to carry out small work and lengthy functions should be broken into small modules for completing small tasks.
- Function return values
- Functions should always return a value. The return value should be of the correct type and named appropriately.
- Error handling
- Error handling should be incorporated in the function design. Developers should use try-catch blocks to handle exceptions and errors.
- Commenting
- Functions should be commented to explain what they do and why they do it. Comments should also explain the input parameters and expected return values.
- Testing
- Developers should write automated tests for their functions to ensure they are working correctly. Test cases should cover different scenarios, including edge cases and error handling.
17. While writing Classes
There are several best practices to keep in mind when writing classes in JavaScript:
- Use the ES6 class syntax
- ES6 introduced a new syntax for defining classes in JavaScript that is more concise and easier to read.
- Use constructor functions
- The constructor function is a special method that is called when an instance of a class is created. It is used to initialize the object’s properties and methods.
- Use static methods and properties
- Static methods and properties are defined on the class itself rather than on instances of the class. They are useful for defining utility functions or constants that are associated with the class
- Use the “this” keyword carefully
- The “this” keyword refers to the current instance of the class. It is important to use it carefully to avoid unintended side effects or errors.
- Use inheritance sparingly
- Inheritance can be a powerful tool for reusing code, but it can also lead to complex and difficult-to-maintain code. Use inheritance sparingly and prefer composition over inheritance where possible.
- Use access modifiers
- JavaScript does not have built-in access modifiers like public and private, but you can achieve similar effects by using naming conventions or closures.
- Use comments and documentation
- Classes can be complex, and it’s important to provide clear and concise documentation to help other developers understand how to use them. Use comments to explain the purpose of each method and property and provide examples where appropriate.
18. While using ‘this’ keyword
In JavaScript, the ‘this‘ keyword is used to refer to the current object.
To use ‘this‘ effectively, it’s important to follow some best practices:
- Use ‘this‘ only when necessary
- Avoid using ‘this‘ unnecessarily. If the current object isn’t needed, use a local variable instead.
- Use’ bind’, ‘call’, or ‘apply‘ to control the value of ‘this‘
- ’bind’, ‘call’, and ‘apply‘ can be used to explicitly set the value of ‘this‘. This is especially useful when passing a method as a callback.
- Use arrow functions to avoid confusion
- Arrow functions have a lexical ‘this‘, meaning that they inherit the value of ‘this‘ from their parent scope. This can help avoid confusion when working with nested functions.
- Be aware of how ‘this‘ behaves with constructors
- When using ‘this‘ in a constructor, be aware that it refers to the newly created object. If you forget to use the ‘new’ keyword when calling a constructor, ‘this‘ will refer to the global object.
- Avoid using ‘this‘ in async functions
- ‘this‘ can behave unexpectedly in async functions, especially when using ‘await’. To avoid confusion, it’s best to use a local variable instead.
19. In General
a) Consistency
Code should be consistent in style, formatting, and structure. This makes the code
easier to read and maintain.
b) Modularity
Code should be modular, with clear separation of concerns. This makes the code
more reusable and easier to test.
c) Error handling
Code should have robust error handling to catch and handle errors gracefully. This
makes the code more reliable and less prone to bugs.
d) Comments and documentation
Code should be well documented with clear comments and documentation that
explain the code’s purpose and usage.
e) Performance optimization
JavaScript developers should be knowledgeable about performance optimization
techniques and apply them when necessary.
f) Security
Code should be written with security in mind, to prevent common vulnerabilities.
g) Code reviews
To ensure that code meets coding standards and best practices.
20. References
- JavaScript | MDN (mozilla.org)
- Code Conventions for the JavaScript Programming Language
- Google JavaScript Style Guide
- JavaScript Standard Style
- WordPress JavaScript Style Guide
- airbnb JavaScript Style Guide
- Coding Standards and Guidelines – GeeksforGeeks
- JavaScript Best Practices (w3schools.com)
- 1 How to write your first SuiteScript – for non-developers – Stoic Software
- Importance of Coding Standard and Code Quality in Software Development (multidots.com)
- goldbergyoni/javascript-testing-best-practices: ?? ? Comprehensive and exhaustive JavaScript & Node.js testing best practices (December 2022) (github.com)
- Documentation is the Key (tutorialspoint.com)
- 30 JavaScript Best Practices for Beginners (tutsplus.com)