ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

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

JavaScript Tutorial• 5 min read

JavaScript Variables & Data Types

Declaring data with let, const, and understanding primitive types

Variables are containers for storing data (storing data values). JavaScript variables can be declared using let, const, or var.

let vs const vs var

const: Used for variables whose values should never change (block-scoped). Always use const by default unless you know the value will be reassigned.

let: Used for variables whose values will change over time (block-scoped).

var: The older declaration keyword (function-scoped). Rarely used in modern ES6+ code.

Variables in JavaScript
// Declaring constants
const siteName = "Codexia";
const maxScore = 100;

// Declaring reassignable variables
let userXp = 40;
let isCompleted = false;

// Performing arithmetic
userXp += 25; // userXp is now 65

console.log("Welcome to", siteName);
console.log("Current XP:", userXp);
Data TypeDescriptionExample
StringTextual characters wrapped in quotes"Hello World"
NumberIntegers and floating point numbers42, 3.14
BooleanLogical true or falsetrue, false
ObjectKey-value dictionary structure{ name: "John", age: 30 }
ArrayOrdered list of items[1, 2, 3, 4]
UndefinedVariable declared without a valuelet x;
NullExplicit representation of empty or nothingnull
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 keyword should you use to declare a variable whose reference should NOT be reassigned?