Curriculum
Concept 06 // Module 01: JavaScript Foundations & Environment
Comments, Identifiers & Reserved Keywords
Module 01: JavaScript Foundations & Environment•Concept 06 of 100• 5 min read
Comments, Identifiers & Reserved Keywords
JavaScript source text is parsed into tokens comprising comments (ignored at execution), identifiers (variable, parameter, and function names), and reserved keywords that are permanently claimed by ECMAScript grammar.
The Core Concept
Syntax Reference
// 1. Single line comment
/* 2. Multi-line comment */
// Legal Identifiers: Must start with Letter, $, or _
let userGreeting = "Hello";
let $totalPrice = 99.99;
let _privateCounter = 0;
// Reserved Keywords (Cannot be used as identifier names):
// let, const, var, function, return, if, else, class, import, export, await, etc.Live Interactive Studio
Identifiers must begin with an ASCII letter, dollar sign ($), or underscore (_). They can be followed by digits, letters, $, or _.
JavaScript Editor
Loading...
Console Output
Waiting for output...
Key Code Patterns in Action
01
Valid vs Invalid Identifier Rules
// Valid Identifiers
let firstName = "Alex";
let $amount = 500;
let _status = "active";
let count2 = 10;
console.log({ firstName, $amount, _status, count2 });
// Invalid Identifiers (Uncommenting causes SyntaxError):
// let 2count = 10; // Error: Cannot begin with digit
// let first-name = 1; // Error: Hyphen parsed as subtraction
// let return = true; // Error: 'return' is a reserved keywordIdentifiers must begin with an ASCII letter, dollar sign ($), or underscore (_). They can be followed by digits, letters, $, or _.
02
Comments & Engine Parsing
// Comments are stripped during the lexical analysis phase
function computeSum(a, b) {
/* Ignored by JS Engine */
return a + b;
}
console.log(computeSum(10, 20)); // 30Comments have zero runtime memory overhead. The scanner strips comments before Abstract Syntax Tree (AST) construction.
03
Valid Identifier Characters
const $amount = 100;
const _privateKey = 'secret';
const café = 'coffee'; // Unicode identifiers are valid!
console.log({ $amount, _privateKey, café });Identifiers can start with letters, $, or _, and support Unicode characters.
04
Reserved Words as Object Properties
// Reserved keywords CAN be used as property keys in ES5+:
const record = { default: true, class: 'A', return: 42 };
console.log(record.default, record.class);While reserved as variable names, keywords are valid object property keys in ES5+.
05
JSDoc Structured Comments
/**
* Adds two numbers.
* @param {number} a
* @param {number} b
* @returns {number}
*/
function add(a, b) { return a + b; }
console.log('Sum:', add(10, 20));JSDoc comments enable IDE autocompletion and rich type annotations without TypeScript.
Real-World Engineering Takeaways
Meaningful Naming: Use camelCase for variables/functions, PascalCase for classes, and UPPER_SNAKE for immutable constants.
JSDoc Documentation: Use `/ ... */` comments for rich IDE type hinting without TypeScript compilation overhead.
Clean Codebases: Remove commented-out code in favor of Git version control history.
Under the Hood: Engine & Memory Mechanics
How JavaScript Executes This
Identifiers exist only as symbol tokens during parsing and compile time. In production bytecode and machine code, identifiers resolve directly into stack offsets or memory register addresses.
Common Pitfalls & Traps
Never attempt to use language keywords as identifiers
let default = 10; // SyntaxError: Unexpected token 'default'Keywords like default, class, delete, and switch are reserved for ECMAScript grammar productions.
Quick Knowledge Check
Test your understanding on these 10 questions (one by one):
Score: 0 / 10
Question 1 of 10 • Core Purpose & Mental Model
What is the core purpose of Comments, Identifiers & Reserved Keywords in JavaScript?
// Concept 6: Comments, Identifiers & Reserved Keywords
// Understanding the core mental model1 / 10