Values

Values are the raw data of your application. A value is a representation of an entity, which the program can manipulate. They are generally atomic units of data, but in some cases can be more complex, and even composed of other values.

There are multiple different sorts of values, and they are differentiated by what is known as a type. Examples of common types are:

Strings

A string is a piece of text. Strings are denoted by words wrapped in quote marks. In Javascript, you can use three different kinds of quote marks

Single Quotes & Double Quotes

strings wrapped in 'single quotes' and "double quotes" have not special behaviour to them and ultimately the choice between them comes down to the situation at hand, and style preferences

Backquotes

strings wrapped in backquotes have special behaviour in JavaScript in that they allow you to inject other values or variables into your strings by wrapping them with ${}. This is called a template string and it looks like this:

var myVariable = 'This is some text which I can inject';
var templateString = `My text is: ${myVariable}`;

Numbers

Integers

Integers are full numbers with no decimals places

Floats

Floats are numbers with a decimal place, followed by a fraction. Floats are used when more precision is required

Booleans

Boolean values are those which are either true or false. They are binary, and are often used for conditional statements

Arrays

an array is basically a list of other values. Arrays are denoted by the square brackets which surround them. the items in an array can be of any type, like so ['some text', 1, 2, 3.14, 'some more text']. The comma separates each of the items, so in this case, the array contains 5 items.

Objects

an Object is a collection of properties, where a property is an association between a name (or key) and a corresponding value. for example, consider the following: { myKey: 'my Value' }. The values can be of any type, such as the ones listed above here. There are some limitations around what you can use as a key, but generally speaking if you stick with a short, descriptive (of the purpose of the value) word, You will generally do okay.

Last updated