DevLearningTools

🚧 This site is under active construction — new tools, guides, and pages are added every week.

MODULE 2 · LESSON 03

Comments

Single-line and multi-line comments in CFScript, the real tag-syntax comment (<!--- --->), and why it isn't the same as an HTML comment.

New lessons are added one at a time as the course gets built out — a graded quiz for each lesson is still on the way.

Every programming language allows you to write notes inside your code. These notes are called comments. Comments are ignored by the ColdFusion engine — they don't affect how your application runs. Their purpose is to help you and other developers understand the code.

As your applications grow, comments become increasingly valuable. A piece of code that makes perfect sense today may be difficult to understand six months later. Good comments explain why the code exists, not just what it does.

By the end of this lesson, you'll know how to write comments in both CFScript and Tag Syntax, understand the difference between ColdFusion comments and HTML comments, and learn when comments are actually useful.

Learning Objectives

After completing this lesson, you'll be able to:

  • Understand what comments are.
  • Write single-line comments.
  • Write multi-line comments.
  • Use comments in both CFScript and Tag Syntax.
  • Understand the difference between HTML comments and ColdFusion comments.
  • Follow best practices for writing comments.

What Are Comments?

Comments are notes written inside your source code. They are useful for:

  • Explaining complex logic
  • Temporarily disabling code
  • Leaving reminders (TODOs)
  • Making code easier to maintain

The ColdFusion engine ignores comments while executing your application.

Single-Line Comments (CFScript)

In CFScript, use two forward slashes (//) to create a single-line comment.

CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
NOTE

Everything after // on that line is ignored.

Multi-Line Comments (CFScript)

Use /* */ when your comment spans multiple lines.

CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.

ColdFusion Comments (Tag Syntax)

Tag-based CFML uses <!--- --->, not an HTML-style comment. This is the comment style you'll actually see in real ColdFusion codebases and frameworks like ColdBox and FW/1. Everything between <!--- and ---> is completely removed by the ColdFusion engine before the page reaches the browser.

tag syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.

HTML Comments vs. ColdFusion Comments

Many beginners confuse these two.

HTML Comment

HTML comments are sent to the browser. If someone opens View Source, they can still see them.

example.cfm
<!-- Developer Note -->

<cfoutput>
Hello
</cfoutput>
browser output
Hello
page source
<!-- Developer Note -->

Hello
NOTE

The comment is hidden on the rendered page but still visible in the HTML source.

ColdFusion Comment

example.cfm
<!---
Developer Note
--->

<cfoutput>
Hello
</cfoutput>
browser output
Hello
page source
Hello
NOTE

The comment is completely removed before the page is sent to the browser.

Quick Comparison

HTML CommentColdFusion Comment
<!-- --><!--- --->
Visible in View SourceNot visible
Processed by BrowserProcessed and removed by ColdFusion
Good for HTML notesGood for CFML notes

Commenting Out Code

Sometimes you don't want to delete code — you simply want to disable it temporarily.

CFScript

cfscript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.

Tag Syntax

tag syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.

TODO Comments

Developers often leave reminders for future work.

CFScript
<cfscript>

    // TODO: Add email validation

</cfscript>
Tag Syntax
<!---
TODO:
Add email validation.
--->

Real-World Example

CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
Tag Syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.

When Should You Write Comments?

Write comments when:

  • Business logic is difficult to understand.
  • A workaround or special case needs explanation.
  • You're leaving notes for other developers.
  • You want to temporarily disable code.
  • You add TODO or FIX comments.

When Should You Avoid Comments?

Don't write comments for code that is already obvious.

unnecessary
// Store age

age = 25;
worthwhile
// Employees below 18 cannot register.

if (age LT 18) {
    writeOutput("Registration denied");
}
NOTE

The best code is often self-explanatory.

Common Beginner Mistakes

Using HTML comments for sensitive information

<!-- Database Password = admin123 --> is visible to anyone who views the page source. Never store passwords, API keys, or confidential information in HTML comments.

Forgetting to remove old comments

A comment like "// Calculates GST" above code that actually applies a flat discount no longer matches what the code does — outdated comments mislead more than they help.

Writing too many comments

Commenting every obvious line, like "// Store name" above name = "John";, adds noise. Good variable names are often enough on their own.

Best Practices

  • Write comments to explain why, not what.
  • Keep comments short and meaningful.
  • Remove outdated comments.
  • Use <!--- ---> for ColdFusion tag-syntax comments.
  • Use HTML comments only for HTML-related notes.
  • Never store passwords, API keys, or sensitive information in comments.

Interview Questions

What are comments?

Comments are notes in the source code that are ignored by the ColdFusion engine.

How do you write a single-line comment in CFScript?

// This is a comment

How do you write a multi-line comment in CFScript?

/* Multiple Line Comment */

What is the standard way to write a comment in tag-based CFML?

<!--- Comment --->

What's the difference between HTML comments and ColdFusion comments?

HTML comments are sent to the browser and can be viewed in the page source. ColdFusion comments are removed by the server before the response is sent, so they are never visible to the browser.

Summary

In this lesson, you learned how to write comments in ColdFusion using both CFScript and Tag Syntax. You explored single-line comments (//), multi-line comments (/* */), and the <!--- ---> comment syntax used in tag-based CFML.

You also learned the important difference between HTML comments, which remain visible in the browser's page source, and ColdFusion comments, which are completely removed before the response is sent to the client.

Well-written comments improve readability and maintainability, but they should explain why the code exists rather than simply repeating what the code already says.

What's Next?

The next lesson covers Operators — arithmetic, assignment, comparison, logical, string, and ternary operators, along with practical examples in both CFScript and Tag Syntax.