Understanding JavaScript Coding Standards
If you know a
#ComputerScience student, a junior
#SoftwareEngineer or anyone who just began to scratch the surface in
#javascript #programming, send them this article on
#programmingprinciples and they'll thank you later 😀 Let's go!
In the dynamic world of JavaScript, coding conventions and rules are essential for maintaining code readability, consistency, and collaboration within teams.
Using coding standards streamlines debugging and reduces errors. It is crucial for beginners and students to understand these standards, as it ensures that code is not only functional, but also clean and easy to comprehend for others.
JavaScript coding standards encompass various aspects of programming, such as:
🔸 Naming conventions
🔸 Code formatting
🔸 Commenting practices
🔸 Error handling
Following these standards ensures that your code is consistent and easy to understand.
Commenting in JavaScript
Comments in JavaScript play a crucial role in making your code understandable and maintainable.
1⃣ Multiple line comments: For comments that stretch over multiple lines, use the multiple line comment format like: /* comment */
2⃣ Single line comments: For short, one-line comments, you can use either the multiple line format or the single line format like: // comment
Here’s what you should include in the comments:
🔸 Description of the function or class
🔸 Parameters – Document each parameter w/ @ param tag.
🔸 Return Value – Document the return value w/ @ return tag.
🔸 Exceptions – Use the @ throws tag to document any exceptions.
To ensure your comments are effective, follow this checklist:
🔸 Clarity – Can someone pick up the code and immediately start to understand it?
🔸 Intent – Do comments explain the code’s intent rather than just repeating the code?
🔸 Moderation – Has tricky code been rewritten rather than over-commented?
🔸 Update – Are comments up-to-date with the code?
🔸 Focus – Do comments focus on why the code is written a certain way rather than how it works?
🔸 Comprehensive – Are the following elements commented on: input and output data, interface assumptions, limitations, sources of algorithms, behavior in error conditions?
🔸 Others – Are magic numbers replaced with named constants rather than just documented? Are the ranges of values commented?
If you answered Yes to all these questions, you’re ready for the next step 🙌
Naming conventions in JavaScript
Naming your variables, functions, and classes properly is also key to writing clean and understandable JavaScript code.
1⃣ Camel case is a case style where the variable or function names are combined and only the second letter is capitalized. This style can be used for more purposes, like:
🔸 Multi-world variables
🔸 Function names
🔸 Function parameters
2⃣ Pascal case is a casing style in which the words for a class or type name are joined together and the first letter of each is capitalized. This style should be used for:
👉 enum like constants, like KernelSystem, KernelState
👉Class names: e.g. UILRouter
👉Default imports: e.g. import UILValidations from “./uil-validations.js”
3⃣ Uppercase is usually used for module level constants, like AUTH_TOKEN_REGEXP.
Understanding JavaScript coding standards is the first step towards becoming a proficient programmer. By adhering to these standards, you ensure that your code is clean, readable, and maintainable.
Read the entire article here:
buff.ly/3ClRJmp
#Hubgets #4PSA #code #codedevelopment #coding #developer #programmer