Namaste! Pichhli lesson mein aapne const aur let se meaningful variables banana, values update karna, aur legacy var syntax ko read karna seekha. Ab hum un variables ke andar rakhi jaane wali actual values ko samjhenge—aur un values ke saath calculations, labels, checks, aur decisions ke inputs banayenge.
Aaj ke end tak aap GEE Code Editor mein numbers, strings, booleans, aur null confidently use karenge; arithmetic, comparison, aur logical operators se expressions likhenge; aur Console mein unka output verify karenge. Yeh small-looking skill later cloud thresholds, date ranges, output names, dataset checks, aur analysis parameters ko reliable banati hai.

Value aur expression: script ki basic language
Value koi actual data item hota hai, jaise 20, 'Sentinel-2', true, ya null.
Expression values, variables, aur operators ka combination hota hai jo ek nayi value produce karta hai.
const cloudThreshold = 20;
const observedCloud = 12;
const remainingAllowance = cloudThreshold - observedCloud;
print('Remaining allowance:', remainingAllowance);
Yahan:
20aur12values hain.cloudThreshold - observedCloudek expression hai.- Expression ka result
8hoga. remainingAllowanceus result ko store karta hai.
Ek important distinction:
const scaleMeters = 10;
Is line mein = ka matlab assignment hai: right-side value ko left-side variable mein store kijiye. Iska matlab mathematical “equal to” nahin hai. Equality check ke liye hum thodi der mein === use karenge.
Is lesson ke liye previous script ki copy banaiye aur ise save kijiye:
03_types_and_operators
Four core values: number, string, boolean, aur null
JavaScript mein value ka type usually aap likhte waqt specify nahin karte. JavaScript value dekh kar type identify karta hai. Isse dynamically typed language kehte hain.
1. Numbers
GIS workflow mein numbers har jagah hain: spatial resolution, cloud percentage, NDVI threshold, year, area, rainfall, temperature, aur class IDs.
const analysisYear = 2023;
const cloudThreshold = 20;
const ndviThreshold = 0.35;
const pixelSizeMeters = 10;
print('Year:', analysisYear);
print('NDVI threshold:', ndviThreshold);
JavaScript mein 20, 0.35, aur -5 sab ka broad type number hota hai. Aapko alag se integer, float, ya double declare karne ki need nahin hoti.
print(typeof analysisYear); // number
print(typeof ndviThreshold); // number
Important:
20ek number hai, lekin'20'ek string hai. Quotes meaning change kar dete hain.
2. Strings
String text value hoti hai. Dataset IDs, district names, band names, dates, export names, aur labels normally strings hote hain.
const districtName = 'Pune';
const datasetId = 'COPERNICUS/S2_SR_HARMONIZED';
const ndviBandName = 'NDVI';
const startDate = '2023-06-01';
print('District:', districtName);
print('Dataset:', datasetId);
String ko single quotes ya double quotes dono mein likh sakte hain:
const seasonOne = 'monsoon';
const seasonTwo = "post-monsoon";
Is course mein consistency ke liye normally single quotes use karenge.
Dates bhi abhi strings hi hain:
const preFloodDate = '2023-07-01';
Later GEE ke date objects aur image filtering mein in strings ko date inputs ke roop mein use karenge. Filhaal unhe text labels samajhiye.
3. Booleans
Boolean value sirf do possibilities rakhti hai:
true
false
Boolean mostly kisi check, status, ya yes/no condition ko represent karta hai.
const useCloudMask = true;
const exportResults = false;
const isTrainingDataReady = true;
print('Cloud mask enabled:', useCloudMask);
print('Export enabled:', exportResults);
true aur false lower-case likhne hote hain aur quotes ke bina:
const correctFlag = true;
const wrongFlag = 'true';
Pehla boolean hai; doosra text string hai. Console mein dono similar dikh sakte hain, lekin JavaScript unke saath different behavior karega.
4. null
null ka meaning hai: variable intentionally exist karta hai, but currently usmein meaningful value nahin hai.
Suppose aapne optional reference year abhi select nahin kiya:
let referenceYear = null;
print('Reference year:', referenceYear);
Yeh useful design choice hai. Aap keh rahe hain: “reference year ka concept hai, lekin abhi value deliberately empty hai.”
Baad mein value assign ki ja sakti hai:
let referenceYear = null;
referenceYear = 2020;
print('Reference year:', referenceYear);
Yahan let use hua because value update hogi. Agar aap const referenceYear = null; likhenge, to later 2020 assign nahin kar sakte.
null ko in forms se confuse na kijiye:
| Form | Meaning |
|---|---|
null | Intentionally no value |
'null' | Text containing four letters: null |
let value; | Variable exists, but JavaScript gives it undefined |
| Variable name hi nahin likha | Usually error, because JavaScript us name ko recognize nahin karta |
Aap previous lesson se undefined dekh chuke hain. Practical rule simple rakhiye:
null: aapne intentionally “no value yet” set kiya.undefined: value assign nahin hui.
Video walkthrough: types ko Console mein inspect karna
Data Types and Operators in Javascript
Piyush Garg ka “Data Types and Operators in Javascript” Hindi/Hinglish mein numbers, strings, booleans, null, arithmetic, aur typeof ko directly code examples se explain karta hai. Video GEE-specific nahin hai, lekin same JavaScript rules GEE Code Editor ke script panel mein apply hote hain.
Watch numbers for integer and decimal values, then strings for quotes and text joining. Continue with boolean and null, focusing on the distinction between an explicit empty value and an unassigned value. For operator basics, watch arithmetic, then finish with typeof to see how type inspection works. The video uses let and sometimes other editor conventions; in your GEE scripts, continue using const for fixed values and let only where reassignment is intended.
Back in GEE, typeof ek useful diagnostic operator hai:
const scale = 10;
const areaName = 'Pune';
const applyMask = true;
const optionalDate = null;
print('scale type:', typeof scale);
print('areaName type:', typeof areaName);
print('applyMask type:', typeof applyMask);
print('optionalDate type:', typeof optionalDate);
Expected output broadly hoga:
number
string
boolean
object
Last output surprising lag sakta hai: JavaScript mein typeof null historically 'object' return karta hai. Yeh language ka old quirk hai. Iska matlab null actual object nahin hai. Aap null ko still “intentionally empty value” hi samajhiye.
Arithmetic operators: GIS parameters par calculations
Numbers ke saath arithmetic operators normal calculation rules follow karte hain.
| Operator | Kaam | Example |
|---|---|---|
+ | Addition | 10 + 5 |
- | Subtraction | 20 - 12 |
* | Multiplication | 10 * 10 |
/ | Division | 100 / 4 |
% | Remainder | 13 % 12 |
** | Power | 10 ** 2 |
Ek simple raster-grid calculation dekhiye. Assume kijiye ki aapke paas -metre pixels wala rectangular raster hai. Yeh sirf JavaScript arithmetic practice hai; later real Earth Engine image area ke liye ee.Image.pixelArea() use karenge.
const rasterWidthPixels = 2000;
const rasterHeightPixels = 1500;
const pixelSizeMeters = 10;
const pixelAreaSquareMeters = pixelSizeMeters * pixelSizeMeters;
const totalAreaSquareMeters =
rasterWidthPixels * rasterHeightPixels * pixelAreaSquareMeters;
const totalAreaHectares = totalAreaSquareMeters / 10000;
print('One pixel area in square metres:', pixelAreaSquareMeters);
print('Total area in square metres:', totalAreaSquareMeters);
print('Total area in hectares:', totalAreaHectares);
Is example mein:
- one pixel area square metres hai;
- raster mein pixels hain;
- total theoretical area hectares hai.
Real geospatial analysis mein projection, valid-data mask, pixel geometry, aur AOI boundary important hote hain. Lekin calculation ka structure—input parameters, intermediate value, final result—exactly wahi reusable thinking pattern hai jo later GEE workflow mein kaam aayega.
Operator precedence aur parentheses
JavaScript pehle multiplication aur division karta hai, phir addition aur subtraction.
const resultOne = 10 + 5 * 2;
print(resultOne); // 20
Agar aap pehle addition chahte hain, parentheses use kijiye:
const resultTwo = (10 + 5) * 2;
print(resultTwo); // 30
Complex GIS formula, threshold, ya index-related calculation mein parentheses readability aur correctness dono improve karte hain. Rule yeh rakhiye: agar calculation dekhte hi unambiguous nahin lag rahi, grouping ko parentheses se explicit banaiye.
+ ka double role: addition bhi, text joining bhi
+ number ke saath addition karta hai:
const preFloodScenes = 8;
const postFloodScenes = 11;
const totalScenes = preFloodScenes + postFloodScenes;
print('Total scenes:', totalScenes);
Lekin do strings ke beech + concatenation karta hai, yani text ko join karta hai:
const districtName = 'Pune';
const outputPrefix = 'NDVI_';
const exportName = outputPrefix + districtName;
print('Export name:', exportName);
Console output:
NDVI_Pune
Readable filename create karne ke liye separators explicitly add kijiye:
const districtCode = 'PUN';
const analysisYear = 2023;
const exportName = 'NDVI_' + districtCode + '_' + analysisYear;
print('Export name:', exportName);
Output:
NDVI_PUN_2023
Yahan analysisYear number hai, lekin text banate waqt JavaScript use string form mein display kar deta hai. Labeling ke context mein yeh fine hai.
Lekin numeric calculation mein quoted numbers avoid kijiye:
const thresholdAsText = '20';
const thresholdAsNumber = 20;
print('Text plus 5:', thresholdAsText + 5);
print('Number plus 5:', thresholdAsNumber + 5);
Output ka logic:
Text plus 5: 205
Number plus 5: 25
'20' + 5 mathematical addition nahin karta. JavaScript 5 ko text bana kar '205' join kar deta hai.
Professional scripting habit:
- calculations, scales, thresholds, years, areas ke liye unquoted numbers use kijiye;
- labels, IDs, dates, dataset names, aur filenames ke liye strings use kijiye;
- JavaScript ke automatic type conversion par depend mat kijiye.
Comparison operators: check ka result hamesha boolean
Comparison operators do values ko compare karke true ya false return karte hain. Isliye booleans manually likhne ke alawa expressions se bhi generate hote hain.
const cloudPercentage = 12;
const cloudThreshold = 20;
const isCloudAcceptable = cloudPercentage <= cloudThreshold;
print('Cloud acceptable:', isCloudAcceptable);
Output true hoga because 12 is not greater than 20.
Useful comparison operators:
| Operator | Meaning |
|---|---|
=== | Strictly equal: value aur type dono same |
!== | Strictly not equal |
> | Greater than |
>= | Greater than or equal to |
< | Less than |
<= | Less than or equal to |
Examples:
const ndviValue = 0.42;
const vegetationThreshold = 0.30;
const districtCode = 'PUN';
print('Vegetated:', ndviValue >= vegetationThreshold);
print('Same district:', districtCode === 'PUN');
print('Different district:', districtCode !== 'NGP');
print('High NDVI:', ndviValue > 0.60);
= aur === ko kabhi mix mat kijiye
const threshold = 20;
Yahan = assignment hai.
const isThresholdTwenty = threshold === 20;
Yahan === comparison hai.
New JavaScript code mein equality check ke liye === aur inequality check ke liye !== prefer kijiye. Loose equality operator == automatic conversion kar sakta hai, which can create avoidable surprises:
const numberValue = 20;
const textValue = '20';
print(numberValue === textValue); // false
Values visually similar hain, but type different hai. Strict comparison us difference ko correctly preserve karta hai.
Logical operators: multiple checks ko combine karna
Remote-sensing workflow mein ek image ya analysis input aksar ek se zyada criteria meet karega. For example:
- cloud percentage acceptable ho;
- selected season ke andar ho;
- required band available ho;
- AOI valid ho.
Logical operators individual boolean values ko combine karte hain.
| Operator | Meaning | Boolean result |
|---|---|---|
&& | AND | Dono conditions true honi chahiye |
|| | OR | Kam se kam ek condition true honi chahiye |
! | NOT | Boolean ko reverse karta hai |
AND: dono checks pass hone chahiye
const isCloudAcceptable = true;
const isWithinStudyPeriod = true;
const isCandidateImage = isCloudAcceptable && isWithinStudyPeriod;
print('Candidate image:', isCandidateImage);
Agar dono true hain, result true hoga. Agar ek bhi false ho, result false hoga.
OR: koi ek valid option chalega
const isKharifWindow = false;
const isRabiWindow = true;
const isCropSeason = isKharifWindow || isRabiWindow;
print('Crop-season image:', isCropSeason);
Yahan result true hoga because Rabi window valid hai.
NOT: check ko reverse karna
const isCloudy = true;
const isClear = !isCloudy;
print('Clear image:', isClear);
isCloudy true hai, to isClear false hoga.
Abhi hum sirf boolean expressions calculate aur print kar rahe hain. Next conditional-logic lesson mein aap in results ke basis par script ko different actions perform karwana seekhenge.
Guided Code Editor practice: one small image-selection report
Neeche ka complete code apne 03_types_and_operators script mein paste karke Run kijiye. Console output ko label by label inspect kijiye.
// Fixed project information.
const regionName = 'Pune district';
const analysisYear = 2023;
const datasetLabel = 'Sentinel-2';
// Numeric parameters and observed metadata.
const cloudThreshold = 20;
const cloudPercentage = 12;
const ndviValue = 0.42;
const vegetationThreshold = 0.30;
// An optional setting that has not been chosen yet.
let referenceYear = null;
// Arithmetic expression.
const cloudMargin = cloudThreshold - cloudPercentage;
// Comparison expressions.
const isCloudAcceptable = cloudPercentage <= cloudThreshold;
const isVegetated = ndviValue >= vegetationThreshold;
// Logical expression.
const isCandidateImage = isCloudAcceptable && isVegetated;
// String expression for a future export name.
const outputName = 'NDVI_' + regionName + '_' + analysisYear;
// Console report.
print('Dataset:', datasetLabel);
print('Reference year:', referenceYear);
print('Cloud margin:', cloudMargin);
print('Cloud acceptable:', isCloudAcceptable);
print('Vegetated:', isVegetated);
print('Candidate image:', isCandidateImage);
print('Output name:', outputName);
// Type checks.
print('cloudThreshold type:', typeof cloudThreshold);
print('regionName type:', typeof regionName);
print('isCandidateImage type:', typeof isCandidateImage);
Is code mein har line ka role clear hai:
- Project settings strings aur numbers mein stored hain.
cloudMarginarithmetic expression se banta hai.isCloudAcceptableaurisVegetatedcomparisons ke results hain, so dono booleans hain.isCandidateImagelogical AND se dono checks combine karta hai.outputNamestring concatenation se banta hai.referenceYearexplicitlynullhai because it is optional and currently unset.
Ab controlled changes karke Console response observe kijiye:
cloudPercentageko28set kijiye.cloudMarginnegative hoga aur cloud checkfalsebanega.ndviValueko0.18set kijiye. Vegetation checkfalsebanega.referenceYear = 2020;line ko finalprint()se pehle add kijiye.nullki jagah2020show hoga.analysisYearke around quotes add kijiye aur phirtypeof analysisYeardekhiye. Value similar dikh sakti hai, lekin typestringho jayega.
Yeh Console-based verification habit later GEE collections, image bands, reducer outputs, aur export configurations troubleshoot karne mein especially useful hogi.
Key takeaways
- JavaScript mein
20number hai,'20'string hai,trueboolean hai, aurnullintentionally empty value hai. - Number use kijiye calculations, thresholds, scales, years, aur measurements ke liye.
- String use kijiye labels, dates, dataset IDs, band names, aur output filenames ke liye.
- Boolean
trueyafalsehota hai; comparisons such ascloudPercentage <= cloudThresholdbhi boolean produce karte hain. nullmeans value deliberately absent; it is different fromundefined.- Arithmetic ke liye
+,-,*,/,%, aur**use hote hain. Complex formulas mein parentheses use karke intended grouping clear rakhiye. +strings ko join bhi karta hai, isliye quoted numbers ko calculations mein avoid kijiye.- Equality check ke liye
===prefer kijiye;=value assign karta hai. &&,||, aur!multiple boolean checks ko combine ya reverse karte hain.
Next lesson mein aap JavaScript arrays banaenge, indexed elements access karenge, aur unhe update karenge. Yeh band lists, date lists, palette values, class IDs, aur multiple analysis settings organize karne ki foundation hai.
Can't find a good explanation? Sign up and we'll make it for you
Sign up