Any difference between void and nil?

Is there any difference between void and nil?
Because if I do:

local a = void
print(a) --> will print `nil`
1 Like

To my knowledge no. Void is meant to signify that there’s nothing actually there to return ie in a function. Which is basically what nil does. Although I recommend you use nil as it’s more understandable to most people.

You should only use void for a function if nothing is returned. But i’m pretty sure you dont have to do this in lua. But in other languages like c++ you do have to signify void.

an example of c++ code:

using namespace std;
void outputSomething() {
	cout << "hi";
}

also because void isn’t a keyword in luau

2 Likes

Luau doesn’t have a keyword/type for void so in your code it ends up trying to find a global variable named void and returns nil because there is no value assigned to that global with that name.

So technically there is no difference between void and nil because former doesn’t even exist in the language, thus evaluates to nil.

5 Likes

Void isn’t a valid type in Lua(u), so it returns nil because it tries to find a variable by the name of “void”, which in this case doesn’t exist.

3 Likes