Mascara JavaScript compiler

Try it Download Buy About Documentation Blog Contact

Built-in Types

Mascara JavaScript has these built-in types:

* (star) - The dynamic type. If you don't want the type-checker to verify operations on a variable, you can declare it as *. You will not get any compile-time type errors, but may of course get run-time errors.

Object - The superclass of all classes. Object is also a dynamic type.

int - an integer number. Is not nullable (that is, can be 0 but not null)

float - a floating point number. Is not nullable (that is, can be 0 but not null)

Number - a floating point number. Can also be null.

boolean and Boolean - true or false. Boolean (which capital B) can also be null.

string and String - A string. String (which capital S) can also be null.

Date - A date/time instance.

Array - the generic array type. Arrays can also be more specific, see parameterized types and Array type literals

Function - the generic function type. Function types can also be more specific, see function types

The types starting with a lower case letter are non-nullable. The only difference between string and String is that string is non-nullable. Same with boolean vs. Boolean and float vs. Number.

Math

The built-in Math-object, is a special case since it cannot be instantiated and cannot be used in type annotations. It works like a static class.

Literals

Literals evaluates to types like this:

A number (eg. 10, -99) has type int

A decimal literal (e.g. 1.5) has type float

A string literal (e.g. "hello") has type string

Keywords true and false has type boolean

Object can be replaced by * if the type is unknown, or a structural type if the structure is known.