ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

Introduction to Computer Programming• 6 min read

Variables, Primitive Types & Memory

Store and manipulate data using primitive types: integers, floats, strings, and booleans, and understand variable allocation.

Variables as Labeled Memory Boxes

A variable is a named reference pointing to a specific location in memory. When you declare let score = 100, the computer allocates a memory address and stores the binary value representing 100.

Every programming language has core primitive types:

Integer: Whole numbers without decimals (e.g. 42, -5).
Float / Double: Numbers with fractional decimal points (e.g. 3.14159).
String: Sequences of characters representing text (e.g. "Hello, World!").
Boolean: Logical flags holding either true or false.
Primitive Variable Declarations
// Number (Integer and Float)
const userAge = 25;
const productPrice = 19.99;

// String
const userName = "Elena Rostova";

// Boolean
const isEmailVerified = true;

console.log("User:", userName, "| Age:", userAge, "| Verified:", isEmailVerified);
ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

Which primitive data type represents binary truth values: true or false?