Variables, Keywords and Comments
Last Updated: 01 Oct 2025
Variables
- Variables are containers for storing data values.
- They are used to hold values of different data types.
- Variables are declared using the
var,let, orconstkeywords.
var a = 10;
let b = 20;
const c = 30;
Note , Difference between var, let and const is that
varis function scoped andletandconstare block scopedvarcan be redeclared and updated butletandconstcannot be redeclaredconstcannot be updated
Rules for variable names:
- Must start with a letter or an underscore.
- Can contain letters, numbers, and underscores.
- Cannot start with a number.
- Reserved keywords cannot be used as variable names.
- Case-sensitive (a and A are different variables).
Naming Conventions:
- Use descriptive names (e.g. user_name, user_age, user_height)
- Avoid abbreviations (e.g. u_name, u_age, u_height)
- Avoid Single Letter Variables (e.g. a, b, c)
Naming Standard:
- camelCase → userName (common in JS)
- PascalCase → UserName (used in classes)
- snake_case → user_name (less common but okay)
- UPPERCASE → USER_NAME (for constants)
2. Keywords
Keywords are reserved words in JavaScript that cannot be used as variable names. Example: let, const, var, if, else, return, function, etc.
3. Comments
Comments are used to explain code or provide additional information.
- Single-line comments start with
//and end at the end of the line. - Multi-line comments start with
/*and end with*/.
// This is a single-line comment
/* This is
a multi-line
comment */