JavaScript Variables — தமிழ்

</>Coding Tamilan.← JavaScript course

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

JavaScript Variables

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

Detailed notesRunnable JavaScriptPractice + answer

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

01 / Understand

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

Use const when the binding will not be reassigned and let when it will. A const object can still have its properties changed; const protects the binding, not every value inside it.

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

02 / Explore

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

Variables என்னன்னு தெரியுமா?

Variables என்பது data values store பண்ண இருக்குற containers. Modern JavaScript (ES6+)-ல variables declare பண்ண மூணு ways இருக்கு: var, let, const.

var, let, மற்றும் const

KeywordScopeReassignableHoistedஎப்போ use பண்றது
varFunctionYesYes (undefined)Avoid — legacy code மட்டும்
letBlockYesNo (TDZ)மாறுற values-க்கு
constBlockNoNo (TDZ)மாறாத values-க்கு

Code anatomy / கோடின் விளக்கம்

CodeMeaning
letKeyword used to declare a variable that can change.
scoreThe variable name.
=Assignment operator.
100The value being assigned.
;Ends the statement.
JavaScript reference fragmentCODE
// var — function-scoped, modern code-ல avoid பண்ணு
var name = "Alice";

// let — block-scoped, reassign பண்ணலாம்
let score = 100;
score = 200; // ✅ Allowed

// const — block-scoped, reassign பண்ண முடியாது
const PI = 3.14159;
// PI = 3; // ❌ TypeError: Assignment to constant variable

Data Types

JavaScript dynamically typed — variables எந்த type of data-வையும் hold பண்ணலாம், runtime-ல type மாறலாம்.

JavaScript reference fragmentCODE
// Primitive Types
let text = "Hello";           // String
let age = 25;                  // Number
let price = 19.99;             // Number
let isActive = true;           // Boolean
let nothing = null;            // Null
let notDefined;                // Undefined
let id = Symbol("id");         // Symbol (ES6)
let bigNum = 9007199254740991n; // BigInt (ES2020)

// Reference Types
let arr = [1, 2, 3];           // Array
let obj = { name: "Bob" };     // Object
let fn = () => {};             // Function

console.log(typeof text);      // "string"
console.log(typeof age);       // "number"
console.log(typeof nothing);   // "object" (historical quirk!)

Quirk: typeof null என்பது "object" return பண்ணும் — இது JavaScript-ன் பழைய bug, backward compatibility-க்காக இன்னும் இருக்கு.

Variable Naming Rules

  • Letter, underscore (_), அல்லது dollar sign ($)-ல ஆரம்பிக்கணும்
  • Letters, digits, underscores, dollar signs use பண்ணலாம்
  • Case-sensitive — myVar-உம் myvar-உம் different
  • Reserved keywords use பண்ண முடியாது
  • camelCase convention follow பண்ணு: myVariableName
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 learner = "Kavi";
let completed = 1;
completed = completed + 2;
console.log(learner + ": " + completed);
எதிர்பார்க்கும் முடிவைப் பாருங்கள்
Kavi: 3
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

Start completed at 4, then add 2.

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

The output is Kavi: 6. Keep completed as let because its binding changes.

தவிர்க்க வேண்டிய தவறு: Assigning a new value to a const binding throws a TypeError. Use let for a changing counter.

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

  • 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.