JavaScript Keywords and Identifiers

In this tutorial, you will learn about JavaScript keywords and identifiers with the help of examples.

JavaScript Keywords

Keywords are reserved words that are part of the syntax in the programming language. For example,

const a = 'hello';

Here, const is a keyword that denotes that a is a constant.

Keywords cannot be used to name identifiers.

Here is the list of keywords available in JavaScript.

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

JavaScript Identifiers

An identifier is a name that is given to entities like variables, functions, class, etc.

Rules for Naming JavaScript Identifiers

The rules for writing identifiers are:

  • Identifier names must start with either a letter, an underscore _, or the dollar sign $. For example,
    const a = 'hello';
    const _a = 'hello';
    const $a = 'hello';
  • Identifier names cannot start with numbers. For example,
    const 1a = 'hello'; // this gives an error
  • JavaScript is case-sensitive. So y and Y are different identifiers. For example,
    const y = "hi";
    const Y = 5;
    console.log(y); // hi
    console.log(Y); // 5
  • Keywords cannot be used as identifier names. For example,
    const new = 5; // Error! new is a keyword.

Note: Though you can name identifiers in any way you want, it's a good practice to give a descriptive identifier name.

If you are using an identifier for a variable to store the number of students, it is better to use students or numberOfStudents rather than x or n.