Basics
JS Reserved Words
JavaScript Reserved Words
JavaScript reserved words like class restrict variable naming.
What Are JavaScript Reserved Words?
JavaScript reserved words are specific words that have a predefined meaning in the language syntax. These words are used to perform specific operations and cannot be used as identifiers such as variable names, function names, or labels. Using reserved words incorrectly can lead to syntax errors or unexpected behavior in your code.
List of JavaScript Reserved Words
JavaScript has a list of reserved words that you should be familiar with. These include control structures, data types, and other keywords:
- Control Structures:
if
,else
,switch
,case
,default
,for
,while
,do
,break
,continue
,return
- Data Types and Values:
boolean
,null
,undefined
,number
,string
,object
- Others:
function
,var
,let
,const
,class
,extends
,import
,export
,new
,this
,super
,try
,catch
,finally
,throw
,debugger
,instanceof
,typeof
,void
Using Reserved Words in Code
Reserved words must not be used as identifiers due to their special roles in JavaScript. Let's look at an example to clarify this rule:
Reserved Words in ECMAScript 6 and Beyond
ECMAScript 6 (ES6) introduced new reserved words that are essential for modern JavaScript development. These include let
, const
, class
, super
, import
, and export
. These additions provide powerful features like block scoping, modules, and class-based object-oriented programming.
Future Reserved Words
JavaScript also has future reserved words that are not currently in use but are reserved for potential future use. These include enum
, await
, and implements
. It's a good practice to avoid using these words as identifiers as well, to ensure compatibility with future versions of JavaScript.
Conclusion
Understanding reserved words in JavaScript is crucial for writing error-free code and utilizing the language's full potential. Always keep the list of reserved words in mind when naming your variables, functions, or classes to prevent syntax errors and ensure your code's integrity.
Basics
- Introduction
- Where To
- Output
- Syntax
- Comments
- Variables
- Scope
- Hoisting
- Errors
- Data Types
- Operators
- Ternary Operator
- Short-Circuit Evaluation
- If Else
- Switch
- Loops
- For...Of/For...In
- Functions
- this Keyword
- Objects
- Arrays
- Strings
- Template Literals
- Numbers
- Number Properties
- Dates
- Math
- Booleans
- Type Conversion
- Destructuring
- Spread/Rest
- RegExp
- Strict Mode
- Modules
- Security Basics
- Debugging
- Best Practices
- Mistakes
- Performance
- Reserved Words
- Sets
- Maps
- Bitwise
- Array Const
- Previous
- Performance
- Next
- Sets