Netscript Data Types and Variables

The Netscript language supports three primitive data types:

Numbers  - Positive numerics, such as integers and floats. Examples: 6, 0, 10.5

Strings  - A sequence of characters that represents text. The characters must be encapsulated by single or double quotes. Example: "This is a string" or equivalently 'This is a string'. Strings are fully functional Javascript strings, which means that all of the member functions of Javascript strings such as toLowerCase and includes are also available in Netscript! 

Boolean  - true or false

Netscript also supports arrays, which are special container objects capable of holding many values. Arrays are described in more detail here on the Arrays page.

Variables can be thought of as named containers. Their purpose is to label and store data. The data stored in the variable can then be accessed and changed by referring to the variable's name. The name of a variable must start with either a letter or an underscore. The rest of the variable name can contain any alphanumeric (letters and numbers), as well as hyphens and underscores.

The Netscript language is untyped, meaning that any variable can hold any of the data types above. The value type of a variable can also change. For example, if a variable initially holds a number, it can later hold a string.

The following shows how you can declare and initialize variables:

After declaring a variable, the values in variables can be used simply by referencing the name. For example:

The first command above will store the value 6 in the variable j. The second command will store the string "This is a string Adding more letters onto the string" into the variable s2.