← Back to Lua Course | Chapter 2: Variables & Types | Lesson 3 of 7

nil और Booleans

nil का मतलब है कोई value नहीं, और एक condition में सिर्फ nil और false false count होते हैं।

In this page:

  1. nil और Booleans

nil और Booleans

nil absent value का type है, और एक variable या table field को nil assign करना इसे remove कर देता है। Booleans true और false हैं। Conditions में सिर्फ nil और false falsy हैं, इसलिए 0 और empty string दोनों truthy हैं।

Note: जब false और nil को अलग बताना ज़रूरी हो, nil से explicitly compare करें, जैसे x == nil।

उदाहरण: nil and booleans

lua
local function truthy(v)
  if v then return "truthy" else return "falsy" end
end
print(truthy(nil), truthy(false))
print(truthy(0), truthy(""))
print(type(nil), type(false))
print(nil == false)

-- Output:
-- falsy	falsy
-- truthy	truthy
-- nil	boolean
-- false
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह मान लेना कि 0 false है
  2. यह मान लेना कि एक empty string false है
  3. false को nil से confuse करना जब ये अलग behave करते हैं
चैप्टर सारांश
  • nil का मतलब कोई value नहीं
  • सिर्फ nil और false falsy हैं
  • 0 और "" truthy हैं
  • Unassigned variables nil हैं
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.