Booleans — தமிழ்

</>Coding Tamilan.← JavaScript course

JavaScript · Lesson 08 / 32 · தமிழ்

Booleans

கருத்தைப் புரிந்துகொள்ளுங்கள். Code-ஐ மாற்றி இயக்குங்கள். ஒரு சிறிய பயிற்சியால் கற்றதை உறுதி செய்யுங்கள்.

Detailed notesRunnable JavaScriptPractice + answer

மூலப் பாட விளக்கங்கள் தமிழில் உள்ளன. கூடுதல் concept, practice மற்றும் answer notes ஆங்கிலத்தில் உள்ளன.

01 / Understand

முக்கியக் கருத்து

A boolean is true or false. Use comparisons to give business rules a clear name, then use that boolean in a decision.

Learning goal: Explain what the example does, predict its result, and change it to solve the practice task.

02 / Explore

விரிவான விளக்கங்கள்

JavaScript-ல Booleans

Boolean என்பது இரண்டு values மட்டுமே represent பண்ணும்: true அல்லது false. Conditions, comparisons மற்றும் logical operations-ல இது use ஆகும்.

Boolean Values

JavaScript reference fragmentCODE
let isLoggedIn = true;
let hasErrors = false;

// Boolean() எந்த value-ஐயும் true/false-ஆ convert பண்ணும்
Boolean(1);          // true
Boolean(0);          // false
Boolean("hello");    // true
Boolean("");         // false
Boolean(null);       // false
Boolean(undefined);  // false
Boolean([]);         // true  ← empty array truthy-ஆ இருக்கு!
Boolean({});         // true  ← empty object-உம் truthy!

Falsy மற்றும் Truthy Values

JavaScript-ல எந்த value-உம் boolean context-ல (if condition மாதிரி) use ஆகும்போது truthy அல்லது falsy-ஆ இருக்கும்.

Falsy Values (8 மட்டுமே)Truthy (மத்த எல்லாமே)
falseNon-empty string: "hello", "false"
0Non-zero number: 1, -1, 3.14
-0Empty array: []
0n (BigInt zero)Empty object: {}
"" (empty string)எந்த function-உம்
null
undefined
NaN
JavaScript reference fragmentCODE
// Falsy — if block run ஆகாது
if (0)         { /* run ஆகாது */ }
if ("")        { /* run ஆகாது */ }
if (null)      { /* run ஆகாது */ }

// Truthy — if block run ஆகும்
if ("0")  { /* WILL run — non-empty string */ }
if ([])   { /* WILL run — empty array truthy! */ }
if ({})   { /* WILL run — empty object truthy! */ }

// Double negation trick — boolean-ஆ convert பண்ண
console.log(!!"hello"); // true
console.log(!!"");      // false
console.log(!!0);       // false

Common gotcha: [] மற்றும் {} empty-யா இருந்தாலும் truthy. Array empty-யா இருக்கான்னு check பண்ண arr.length === 0 use பண்ணு — if (arr) மட்டும் போதாது.

03 / Read & predict

முழுமையான உதாரணம்

Run this complete index.js program in the JavaScript console editor below. The earlier reference fragments may need a browser page or other surrounding setup.

index.js · complete exampleCODE
const age = 18;
const hasTicket = true;
const canEnter = age >= 18 && hasTicket;
console.log(canEnter);
console.log(Boolean("false"));
எதிர்பார்க்கும் முடிவைப் பாருங்கள்
true
true
04 / Experiment

மாற்றி இயக்கிப் பாருங்கள்

Load the example, change a value, predict the output, and run it again. Use the console output to check your reasoning.

Open editor ↗

Editor load ஆனதும் code-ஐ ஏற்றி Run அழுத்துங்கள்.

OneCompiler என்ற இலவச வெளிப்புற சேவை code-ஐ இயக்குகிறது. Run செய்யும் code அங்கு அனுப்பப்படும். தனிப்பட்ட தகவல்கள் அல்லது secret keys உள்ளிட வேண்டாம்.

05 / Your turn

சிறிய பயிற்சி

Practice challenge

Set hasTicket to false. Explain why the first result changes.

விடை மற்றும் விளக்கம்

canEnter becomes false because both conditions must be true for &&.

தவிர்க்க வேண்டிய தவறு: The non-empty string "false" is truthy. It is not the boolean false.

அடுத்த பாடத்திற்குத் தயாரா?

  • Explain the example in your own words.
  • Complete the challenge before revealing its answer.
  • Describe the common mistake and how to avoid it.
Coding Tamilan · Learn by doing.