Mascara: Next Generation JavaScript compiler

Try it Download Buy About Documentation Blog Contact

Union types

A union is a type where the value can be an member one of several distinct types or classes.

Syntax:

Syntax definition [Help]
( type [ | type ]* )

Example:

var x : (int|Date); // x is either an int or a Date
x = 17; //OK
x = new Date(); //OK
x = "hello"; //ERROR

An union type is nullable if just one of the ingredients is nullable. For example, in the code above x is nullable because Date is a nullable type.

X Try!
Mascara JavaScript Generated JavaScript

Translating...
Show compiler settings