JavaScript Keywords and Identifiers

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
yield        

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,
    //valid
    const a = 'hello';
    const _a = 'hello';
    const $a = 'hello';
  • Identifier names cannot start with numbers. For example,
    //invalid
    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,
    //invalid
    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.

Did you find this article helpful?

Our premium learning platform, created with over a decade of experience and thousands of feedbacks.

Learn and improve your coding skills like never before.

Try Programiz PRO
  • Interactive Courses
  • Certificates
  • AI Help
  • 2000+ Challenges