Skip to content
Chung Leong edited this page Apr 28, 2024 · 4 revisions

The literal null in Zig is represented as null in JavaScript. You will only encounter it if you explicitly export null.

pub const Null = null;
import { Null } from './null-example-1.zig';

console.log(Null);
null

As @TypeOf(null) is a comptime type, you can only put it into a struct if you make it a comptime field:

pub const NumberAndNothing = struct {
    number: i32,
    comptime nothing: @TypeOf(null) = null,
};
import { NumberAndNothing } from './null-example-2.zig';

const struct = new NumberAndNothing({ number: 1234 });
console.log(struct.valueOf());
Clone this wiki locally