What does ? mean?

Recently saw ? being used for parameters and have no clue what it exactly means or does.
example: function print(Message: string?)

2 Likes

Using ? in your typing means that the parameter is optional!

it means that the message parameter has to be a string if it is provided. If the ? was not there the argument would be required.

This is part of typechecking. Basically adding ? means that the script will asume the parameter can be the type specified or nil. Here’s a brief example:

image

1 Like

To summarize: Using the question mark symbol after the type notation, means the argument doesn’t need specification. It can be the said variable (e.g string, number, boolean), or nil.

It’s called “type checking”, and I highly advise you read the post linked below. It’s how I figured out everything relating to type checking to begin with.

1 Like