Not Value vs. Value == false

I have some scripts checking a value every RunService.RenderStepped, and I’m worried about having the script doing extra computation when checking if the value is or is not false, that’s why I’m wondering if there is any difference between using:

if not Value then
   print("Value is false")
end

or using

if Value == false then
   print("Value is false")
end

There is any extra computation or errors that could happen?

Wrong. not nil returns true while nil == false returns false because nil evaluates to false while it doesn’t equal to false.
Explain this if it’s exactly the same:
image

2 Likes

It’s nothing to do with instances.

not will return true for nil or false values, and false for anything else (incl. strings, numbers, tables, functions, etc.).

== true will only return true if the value is true. Strings, numbers, tables, nil values, false booleans, functions, userdata values and everything else will return false.

You have absolutely no idea what values or what form their variable Value can take, so it is categorically wrong to say the operators are the same in this situation without additional information - nothing to do with whether you’re checking if an instance exists.

4 Likes

Although it’s true that nil == false returns false and not nil returns true. But a screenshot with javascript code which has, compared to lua, very weird equal operators doesn’t really help.

The main thing I think OP should take into account is that computation time of logic is basically negligible. Yes there are errors that could happen if you’re using them incorrectly, refer to @BanTech’s post, but don’t worry abt extra computation

2 Likes