Type ‣ Null - chung-leong/zigar GitHub Wiki

JavaScript | PHP


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

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

console.log(null_value);
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());
{ number: 1234, nothing: null }

Types