Scripting in Java Tutorial - Scripting in Java Identifier

An identifier is a name for variables, functions, labels in scripts.

An identifier in Nashorn is a sequence of Unicode characters with the following rules:

  • may contain letters, digits, underscores, and dollar signs
  • must not start with a digit
  • must not be one of the reserved words


The following are examples of valid identifiers:


The following are invalid identifiers:

4num    //Cannot start with a digit
emp id  //Cannot contain spaces
emp+id  //Cannot contains the + sign
break   //break  is a reserved word and cannot be used as an identifier


The List of Reserved Words in Nashorn Used as Keywords

break         do           instanceof       typeof
case          else         new              var
catch         finally      return           void
continue      for          switch           while
debugger      function     this             with
default       if           throw
delete        in           try

The List of Future Reserved Words in Nashorn

class       enum        extends     super
const       export      import

The List of Future Reserved Words in Strict-Mode in Nashorn

implements      let           private      public
yield           interface     package      protected


Nashorn supports two types of comments:

  • Single-line comments
  • Multi-line comments

The syntax for writing comments in Nashorn is the same as that of Java.

The following are examples of comments:

// A single-line comment
var Id;

   A multi-line comment
var et;
var d;