Skip to content
Chung Leong edited this page Feb 10, 2024 · 8 revisions

Zig enums are represented as unique objects in JavaScript.

const std = @import("std");

pub const Pet = enum { dog, cat, dragon };

pub fn print(pet: Pet) void {
    std.debug.print("pet = {s}\n", .{@tagName(pet)});
}
import { Pet, print } from './enum-example-1.zig';

console.log(typeof Pet.dog);
print(Pet.dog);
print(Pet.cat);
object
dog
cat
Clone this wiki locally