List of generic JavaScript types — Soft8Soft
Description: The list of JavaScript types which are commonly used in 3D applications made with Verge3D.

# Generic JavaScript Types

JavaScript is a dynamically-typed language which offers powerful yet easy-to-use typing system. This however imposes responsibility to track the types of your variables passed to Verge3D API methods. Misusing types might lead to complicated issues, so be careful and always consult with the Verge3D docs in case of any doubts.

## #Any

Any type. There is no such type in JavaScript — this virtual type is used in Verge3D only for documentation purposes.

## #ArrayBuffer

Buffer which stores arbitrary binary data. The content of this buffer is accessible via TypedArray.

`const buffer = new ArrayBuffer(8); const view = new Uint16Array(buffer); // 4 16-bit zeros`

## #Array

JavaScript Array value:

`const numArray = [1, 2, 3, 4]; const strArray = ['A', 'B', 'C']; const emptyArray = [];`

## #Boolean

Boolean value, either `true` or `false`. Using other data types to represent boolean values, such as `''` (empty string), `1` (one), `0` (zero), `null` is not recommended.

## #Constant

Verge3D constant which is accessible from the `v3d` namespace, e.g: `v3d.ESMShadowMap`, `v3d.RGBAFormat`, `v3d.MOUSE.LEFT`, etc. All Verge3D constants are described in the corresponding sections of this reference.

## #Float

Float value such as `3.14`, `-5.0`, or `1e6` (a million). For some Verge3D API methods or properties, you can also use the `Infinity` and `-Infinity` values.

## #Function

JavaScript function. In the context of Verge3D API, this means you need to pass some pre-defined callback function as parameter to an API method or define some event handler.

`function myCallback1(param) { // code goes here } const myCallback2 = function(param) { // code goes here } const myCallback3 = (param) => { // code goes here }`

## #HTMLCanvasElement

HTML `<canvas>` element.

## #HTMLElement

HTML element of any type.

## #HTMLImageElement

HTML image (`<img>`) element.

## #Image

HTML image (`<img>`) element.

## #ImageBitmap

Represents an image bitmap.

## #Integer

Integer value such as `10`, `290`, `-1`, or `0xff0000` (hex value for color red).

In JavaScript there is no specific data type for integers, so difference between floats and integers is purely logical. In the essence, `10` is same as `10.0`, but in Verge3D context these are different types.

## #null

JavaScript `null` object. In most cases this means that the data is not available or is empty.

## #Object

Generic JavaScript object. In most cases this means you need to use the dictionary-like datatype:

`const myObj = { name: 'John Smith', age: 40 }`

When using spaces or other non-alphanumeric characters for keys, put them in quotes or double quotes:

`const myObj = { 'person name': 'John Smith', 'age#': 40 }`

## #String

String value, such as `'Hello World!'`. You can also use the double quotation marks to represent strings, e.g `"Hello World!"`.

## #this

JavaScript `this` value. In most cases, we use `this` to describe methods which return the reference to the same class instance. This allows such methods to be chained, e.g:

`// [0, 0, 0] → [10, 0, 0] → [11, 1, 1] → [6, 0, 0] new v3d.Vector3().setX(10).addScalar(1).sub(new v3d.Vector3(5, 1, 1));`

By definition, all constructors return `this` value, so we don't mention it in the reference.

## #TypedArray

JavaScript typed array value:

`const array1 = new Uint32Array([1,2,3]); // three unsigned 32 bit integers const array2 = new Float32Array(1000); // 1000 zeros, floats with 32 bit precision`

The following types are the most frequently used in Verge3D:

Type | Usage
--- | ---
Float32Array | Positions, normals, UVs, animations.
Uint8Array | Index buffers for small meshes.
Uint16Array | Index buffers for medium meshes.
Uint32Array | Index buffers for large meshes.

## #undefined

JavaScript `undefined` type. As implied by the name, a variable, property, or a function parameter is not defined. Also, JavaScript functions which do not return any values have `undefined` as their return value.