Lexical structure

From Unify Community Wiki
Jump to: navigation, search



Javascript for Unity is written inside of one or more script files. Each of these script files contains at least one class definition which must have the same name as the file, e.g. MyJavascript.js will contain the definition for the MyJavascript class. If no class is explicitly created, then Unity will automatically create a class with the correct name, and anything found inside of that file will be made a member of that class.



Keyword is an identifier-like sequence of characters that is reserved.

Keyword : one of

  • as
  • boolean
  • break
  • byte
  • case
  • char
  • class
  • continue
  • default
  • double
  • else
  • enum
  • false
  • float
  • for
  • if
  • in
  • int
  • long
  • new
  • null
  • private
  • protected
  • public
  • return
  • sbyte
  • static
  • string
  • super
  • switch
  • this
  • true
  • typeof
  • uint
  • ulong
  • ushort
  • virtual
  • void
  • while


A literal is a source code representation of a value

Boolean literals

There are two boolean literal values: true and false
The type of a boolean literal is boolean

Integer literals

Integer literals are used for values of type int, uint, long, and ulong
Integer literals can be of type decimal-integer-literal or hexadecimal-integer-literal
Decimal integer literal
Decimal integer literals are made of decimal-digits
Decimal digits
one of:
0 1 2 3 4 5 6 7 8 9
Hexadecimal integer literal
Hexadecimal integer literals are made of hexadecimal-digits
Hexadecimal digits
one of:
0 1 2 3 4 5 6 7 8 9 A B C D E F a b c d e f

Real literals

Real literals are used to write values of float and double
Real literals can be written as:
decimal-digits . decimal-digits
. decimal-digits
In real literals, a decimal point must be followed decimal digits. Therefore 1.0 is valid, but 1. is not

String literals

String literals consist of zero or more characters enclosed in double-quote characters.
A string literal is of type String

Null literal

The keyword null makes a null literal of type null
Personal tools