Skip to main content

Numeric

Varjus provides built-in support for numeric types, including integers, unsigned integers, and floating-point numbers. These types are designed for efficiency and precision, allowing developers to perform arithmetic and numerical computations seamlessly.

Boolean Type

A boolean type for representing logical values. Boolean values can be either true or false.

let isReady = true;
let isFinished = false;

Integer Types

Integer types represent whole numbers and can be explicitly declared signed or unsigned.

Signed Integers

Signed integers store both positive and negative whole numbers.

const a = 42;    // Signed integer
const b = -15; // Negative signed integer

Unsigned Integers

Unsigned integers can only store non-negative values. You can declare an unsigned integer by suffixing the literal with U or u.

const c = 42U;   // Unsigned integer
const d = 100u; // Equivalent unsigned integer

⚠️ Unsigned integers get implicitly coerced into integers

const expression = 20 + 20u; // int + uint
console.log(typeof expression); // int instead of uint

Floating-Point Types

Floating-point numbers store decimal values and use double-precision representation.

const e = 3.14;  // Double-precision floating-point
const f = -0.001;

Hexadecimal Literals

Numbers can be written in hexadecimal format using the 0x prefix.

const g = 0x2A;   // 42 in hexadecimal
const h = 0xFFU; // 255 as an unsigned integer