Your Page Title
🔍

    JavaScript Reserved Words

    In JavaScript, reserved words (also called keywords) are words that have special meaning in the language syntax. These words are used to define language constructs—such as loops, conditions, and functions—and cannot be used as identifiers, such as variable names, function names, or object property keys (in some cases).

    Using a reserved word incorrectly will lead to syntax errors or unexpected behavior. This tutorial covers everything you need to know about JavaScript reserved words to avoid these issues.


    What Are Reserved Words?

    Reserved words are words that JavaScript has already defined for its own use. They are part of the language grammar and are used to perform specific functions.

    Examples:

    • if, else, for, while, function
    • return, break, continue, switch
    • var, let, const, class

    You cannot use them as variable or function names:

    javascriptCopyEdit// ❌ Invalid
    let if = 5;        // SyntaxError
    function return() {}  // SyntaxError
    

    Categories of Reserved Words

    1. JavaScript Keywords

    These are used to perform built-in operations:

    javascriptCopyEditbreak, case, catch, class, const, continue,
    debugger, default, delete, do, else, export,
    extends, finally, for, function, if, import,
    in, instanceof, let, new, return, super,
    switch, this, throw, try, typeof, var,
    void, while, with, yield
    

    Each of these words plays a specific role. For example:

    • if, else – Conditional logic
    • for, while – Loops
    • function, return – Defining and controlling functions
    • let, const, var – Declaring variables

    2. Future Reserved Words

    These are not used in the language now but may be in future versions. Avoid using them to prevent future compatibility issues.

    javascriptCopyEditenum, implements, interface, package, private,
    protected, public, static, await
    

    Some of these words are reserved only in strict mode (more on that later).

    3. Literals

    Literals represent fixed values and are also considered reserved:

    javascriptCopyEdittrue, false, null
    

    ECMAScript Versions and Reserved Words

    JavaScript is standardized under ECMAScript (ES). Different versions have introduced new reserved words:

    • ES5 (2009) added strict mode and reserved more keywords.
    • ES6 (2015) introduced class, const, let, yield, and super.

    Note: Even if a reserved word isn’t in use today, it may become one in the future. It’s a good idea to avoid any word that looks like a language feature.


    Strict Mode and Reserved Words

    Strict mode ("use strict";) enables stricter parsing and error handling in JavaScript. In strict mode, even more words are reserved.

    Example:

    javascriptCopyEdit"use strict";
    let implements = 5; // SyntaxError in strict mode
    

    To enable strict mode:

    javascriptCopyEdit"use strict";
    

    This is useful for catching errors early, including incorrect use of reserved words.


    Avoiding Reserved Word Issues

    ✅ Do This:

    Use descriptive and unique names for variables and functions.

    javascriptCopyEditlet userName = "Alice";
    function getUserProfile() {
      // code here
    }
    

    ❌ Don’t Do This:

    javascriptCopyEditlet class = "Math";      // ❌ SyntaxError
    function export() {}     // ❌ SyntaxError
    const let = 10;          // ❌ SyntaxError
    

    These will throw errors because class, export, and let are reserved.


    Reserved Words in Object Keys

    You can use reserved words as object keys (in non-strict situations), but it’s still not recommended:

    javascriptCopyEditconst obj = {
      if: "condition",
      return: "value"
    };
    
    console.log(obj.if); // Works, but not ideal
    

    Best practice: Use descriptive and non-reserved names to avoid confusion.


    Complete List of Reserved Words (ES6+)

    textCopyEditbreak, case, catch, class, const, continue,
    debugger, default, delete, do, else, export,
    extends, finally, for, function, if, import,
    in, instanceof, let, new, return, super,
    switch, this, throw, try, typeof, var,
    void, while, with, yield,
    enum, await, implements, package, protected,
    interface, private, public, static
    

    Conclusion

    Understanding JavaScript reserved words is essential for writing valid and error-free code. These keywords are reserved by the language for specific tasks, and misusing them can break your programs.

    To summarize:

    • Reserved words have special meaning and cannot be used as names.
    • JavaScript enforces these rules strictly—especially in "use strict" mode.
    • Avoid reserved words in variables, functions, and class names.
    • Use clear, descriptive identifiers instead.

    By avoiding reserved words and using meaningful names, you’ll write cleaner, more maintainable JavaScript code.