Why is type (nil) == nil false?

I am reading the book "Programming in Lua" and I do not understand exercise 2.1:

What is the meaning of the expression

type (zero) == zero?

(You can use Lua to check your answer.) Can you explain this result? "

When I execute this code, I get "false" as the result. I could not explain this result, from my point of view the correct result should be "true". I tried

type(some_undeclared_variable)==nil 

and he also gives me a "lie."

+4
source share
1 answer

The function type()always returns a string, the value type(nil)is a string "nil"that does not match nil, they have a different type.

+7
source

Source: https://habr.com/ru/post/1584843/


All Articles