Sunday, November 17, 2024
Google search engine
HomeLanguagesJavascriptJavaScript SyntaxError “variable” is a reserved identifier

JavaScript SyntaxError “variable” is a reserved identifier

This JavaScript exception variable is a reserved identifier occurs if the reserved keywords are used as identifiers.

Message:

SyntaxError: The use of a future reserved word for an identifier is invalid (Edge) SyntaxError: “x” is a reserved identifier (Firefox) SyntaxError: Unexpected reserved word (Chrome)

Error Type:

SyntaxError

What happened?

When Reserved keywords are used as identifiers they will throw an error. enum is reserved in both strict and sloppy modes. while the following keywords are reserved in strict mode.

  • implements
  • package
  • public
  • interface
  • private
  • protected
  • let
  • static

Example 1: The package is an identifier in strict mode, So it will work fine here.

Javascript




let package = "This is GeeksForGeeks";
console.log(package);


Output:

This is GeeksForGeeks

Example 2: The enum is an identifier, So it will throw SyntaxError.

Javascript




let enum = "This is GeeksForGeeks";
console.log(enum);


Output:

SyntaxError: Unexpected reserved word
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments