Labs ICT
Pro Login

Reserved Words

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);
Try it Yourself →

Valid Naming Workaround

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

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"]);
Try it Yourself →

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