Keyword Comments

October 10, 2024

Keyword comments are used to attach search terms to your code.

// # create
function CreateItem() {
  // ...
}

When you're looking for a piece of code and a keyword or two comes to mind, adding those keywords as comments can make it much easier to find the code later.

Just make sure to keep it short. Only the first search term is impactful, after all.


***


You can stack keywords by separating them with a comma for readability.

For example, let's say you might naturally search for the CreateItem() function using both the terms "create" and "insert":

// # create, # insert
function CreateItem() {
  // ...
}

Pretty handy, right?

I started using this in C# and JS projects in mid-2024. Nowadays, I rarely remember function names or naming conventions—I mostly search by keywords.


***


On a side note, since this is a new approach for my project team, I’ll need to ask for permission before adding these types of comments to the team's codebase. I'm glad I did.


Editorial link:

blog-posts [workspace]: vanillawebdev/js/keywords-comment.html

Comments

Thank You

for your visit