JavaScript Keywords

What are JavaScript Keywords

In JavaScript, keywords are reserved words that have specific meanings in the JS language.

They are essential components of the syntax and structure of JavaScript programming language.

They cannot be used as variable names, function names or identifiers in your code.

Variable Declaration Keywords

  • var : It is used to declare a function-scoped variable.
  • let : It is used to declare a block scope variable.
  • const : It is used to declare a block-scoped constant.

Control Flow Keywords

  • if : It is used to create a conditional statement where a block of code is executed if a specified condition is true.
  • else : It is used in 'if' conditional statement to execute a block of code if the 'if' condition is false.
  • switch : It is used to create many conditional statements (conditional branching) to specify an alternative block of code to be executed.
  • case : It is used to define a case inside a switch statement.
  • default : It is used to define the default case in a switch statement.
  • for : It is used to create a 'for' loop that runs for a specified number of times.
  • while : It is used to create a 'while' loop that runs as long as a specified condition is true.
  • do : It is used to execute a block of code at least once before checking the condition in a 'do while' loop.
  • break : It is used to exit or stop a loop or switch statement.
  • continue : It is used to skip the current iteration of a loop and continue with the next iteration.

Function Keywords

  • function : It is used to declare a function before function name.
  • return : It is used to exit a function and return a value.

Object-Oriented Programming Keywords

  • class : It is used to declare a class.
  • constructor : It is used to define a constructor method for a class.
  • extends : It is used to define inheritance between classes.
  • super : It is used to refer to the parent class in inheritance.
  • this : It is used to refer to the current object.

Error Handling Keywords

  • try : It is used to execute code and catch exceptions.
  • catch : It is used to define a block of code that handles errors.
  • throw : It is used to throw an exception.
  • finally : It is used to execute code after 'try' and 'catch' blocks, regardless of the outcome.

Other Keywords

  • new : It is used to create an instance of an object.
  • delete : It is used to delete a property from an object.
  • typeof : It is used to returns the type of a variable.
  • instanceof : It is used to check if an object is an instance of a class.
  • in : It is used to check if a property exists in an object.
  • void : It is used to signify the absence of a value.
  • yield : It is used to pause and resume a generator function (pause execution and return a value).
  • async : It is used to declare an asynchronous function.
  • await : It is used to pause an async function until a promise is resolved.
  • import : It is used to import functions, objects, or primitives from another module.
  • export : It is used to export functions, objects, or primitives from a module.
  • use strict : It is used to activate strict mode, which enforces stricter parsing and error handling.
  • debugger : It is used to invoke the debugger.
  • true : It is used for boolean literal for the true value.
  • false : It is used for boolean literal for the false value.
  • null : It is used to represent the absence of any object value.
  • undefined : It is used to indicate that a variable has been declared but not yet assigned a value.