#what is undefined

1 messages · Page 1 of 1 (latest)

grizzled ibex
placid ginkgo
#

You should only use undefined in situations where you know that you will not ever read the value when it is undefined.

grizzled ibex
#

So so I need to check if a is undefined in if-statements? If so; how do I best check this? 🤔

placid ginkgo
#

no, you should be using null

grizzled ibex
#

Huh? Is there a null in Zig? 🤔

placid ginkgo
#

yes, but it must be explicitly allowed to be null in the type

#

e.g. u32 can only be u32 values, but ?u32 can be all u32 values or null

grizzled ibex
#

Ah ok. Thank you so much for letting me know. 🙏

#

I just discovered Zig so I am very new to it. Reading through the docs trying to understand the basics. ☺️

placid ginkgo
#

Good luck 🙂

grizzled ibex
#

Thank you @placid ginkgo ! 🙏

wide warren
#

@grizzled ibex keep in mind that undefined doesn't really exist as a value in runtime. it's a way to tell the compiler to leave the value uninitialized in memory. var foo: u32 = undefined; doesn't assign anything at runtime, it only allocates the space for the variable and doesn't touch its contents

#

null is a real value that will be assigned at runtime, and so you can check for it