Variables

Last updated: Mar 4th, 2018

Introduction

Variables in Cuneiform are declared with the "var" keyword, followed by the variable name. There are two types of variables in Cuneiform.

  1. Global variables
  2. Node local variables

Naming

  • Variable names are case sensitive. A variable's name can be any legal identifier:
    • An unlimited length sequence of unicode letters and digits.
    • Can contain letters, digits, underscores, and dollar signs ($).
  • If the selected name consists of one word, spell that word in lowercase letters. If it consists of more than one word, the first word must be lower case, and the first letter of each subsequent word must be capitalized (camel case). The names orderData, selectedSize, etc.
  • Reserved words (like Cuneiform keywords) cannot be used as variable names.

Examples

Similar to languages like Javascript, Cuneiform variables are containers for storing data values. In this example, x, y, and z are variables.


var x = 5;
var y = 3;
var z = x + y;
                                    

From the example above, you can expect

  • x stores the value 5
  • y stores the value 3
  • z stores the value 8

Declaring (creating) Cuneiform Variables

Creating a variable in Cuneiform is called "declaring" a variable. Variables are declared with the var keyword.

var age;

After the declaration, the variable has a value of null. To assign a value to the variable, use the equal sign.

age = 22;

You may also assign a value to the variable when it is declared.

var age = 22;

Cuneiform Data Types

Cuneiform variables can hold numbers such as 100, and text values like "John Doe". In programming, text values are known as "strings".

Strings are written inside double quotes. Numbers are written without quotes. If a number is put in quotes, it will be treated as a text string. For example,


var pi = 3.14;
var name = "John Doe";
var age = 22;
                                    

In addition to numbers and strings, Cuneiform can handle many types of data such as Objects, Arrays, and System operations.

Cuneiform Arithmetic

Similar to algebra, we can perform arithmetic with Cuneiform variables, using operators such as = and +. Some examples are as follows:


var x = 5 + 2 + 3;
var y = -10;
var z = (x + y) * 100 - (-30);
                                    

Strings can also be added, but they will be concatenated.


var firstName = "John";
var lastName = "Doe";
var fullName = firstName + " " + lastName;
                                    

What's next?

Objects and Arrays are types of Cuneiform variables that can hold multiple amounts of data. In the next section, we will discuss them in more detail.