Ad space (banner)
๐ŸŸฃJulia Lessons
Lesson 21 / 68

Writing nothing-safe code

This lesson covers handling values safely against nothing in Julia, with the aim of preventing errors when a value has not been set.

Julia represents "no value has been set" with nothing. Comparing with === nothing tells you whether a value is nothing.

The sample code declares address = nothing, tests it with if address === nothing, and shows an alternative message when it is. Note the use of === rather than ==.

A common early stumble is the difference between nothing and missing. Julia has two similar-looking concepts — nothing for "no value exists" and missing for "missing value" — and they need to be used distinctly.

In professional work, handling missing data comes up constantly in numerical work, so getting nothing and missing right directly affects how much you can trust your code.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Julia directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)