Labs ICT
⭐ Pro Login

Reserved Words

1 min read | JavaScript Tutorial
⭐

Want the full learning experience?

Get structured courses, certificates, projects, and instructor support with LabsICT Pro.

Explore Pro Courses

Reserved Words

JavaScript reserves certain words for its own use. You cannot use these as variable names, function names, or identifiers. Trying to do so will throw a syntax error or cause unexpected behavior.

Common reserved words: if, else, for, while, do, switch, case, break, continue, return, function, var, let, const, class, new, this, typeof, instanceof, try, catch, finally, throw, import, export, async, await, yield, debugger, with, void, delete, in, of, null, true, false, undefined, NaN, Infinity.

Reserved Word Error

// This will cause an error:
// let if = 5;

let name = "Alice";
console.log(name);

Valid Naming Workaround

let ifCondition = true;
let className = "highlight";
let returnValue = 42;
console.log(ifCondition, className, returnValue);

Class Names and Reserved Words

// You can use reserved words as object keys
let obj = {
  class: "first",
  return: "yes",
  default: "none"
};
console.log(obj.class);
console.log(obj.return);
console.log(obj["default"]);

Reserved words are fine as object property names (with quotes if needed), just not as bare identifiers.