Nil ()
Literals
Post
Nil Literal
The nil
basic type has only a single value called nil
. Nil literal uses the syntax ()
and null
.
✍ Syntax
Nil Literal
()
| null
Code Breakdown
- Line 5: nil literal
()
is assigned to the variablea
. - Line 6: nil literal
null
is assigned to the variableb
.
💡 Note: Both ()
and null
are equivalent to nil
in Ballerina. However, ()
is the preferred way to assign nil value to a variable.