JavaScript Syntax & Comments

Values, literals, identifiers and comments.

✍️ 3 exercises + code challenge in this lesson

JavaScript syntax is the set of rules for writing programs.

  • Literals are fixed values: 10.5, "Ali", true.
  • Variables store values: let x = 10;
  • Identifiers (names) start with a letter, _ or $ and are case-sensitive: total and Total are different.
  • The convention is camelCase: firstName, totalPrice.

JavaScript Comments

// single-line comment and /* multi-line comment */. Comments explain code and can disable lines while testing.

Key Takeaways: JavaScript Syntax & Comments

Mastering JavaScript Syntax & Comments helps you write clean and reliable JavaScript code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

JavaScript Syntax & Comments Code Example

JavaScript
<pre id="out"></pre>
<script>
const log = (...a) => document.getElementById("out").textContent += a.join(" ") + "\n";
// This is a single-line comment
let firstName = "Sara";   // camelCase identifier
let FirstName = "Ayesha"; // a different variable (case-sensitive)

/*
  This is a multi-line comment.
  log("This line does not run");
*/
log(firstName, "and", FirstName);
</script>
Free sign-in required · Google login available

JavaScript Syntax & Comments Practice Exercises

Check what you learned in “JavaScript Syntax & Comments”.

/ 3 solved
Fill in the blank

Write a single-line comment.

 This line is ignored
✓ Correct! Not quite. Try again.
Multiple choice

Are firstName and FirstName the same variable?

✓ Correct! Not quite. Try again.
Code challenge

Two lines print. Turn the second log into a comment so only "Keep me" is printed.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services