New! Explore our Programming Academy and AI Tutor - learn to code from scratch, free to start. Explore Now
Programming JavaScript JavaScript Basics

JavaScript Basics

JavaScript

Variables, data types, and basic operations in JavaScript.

Lesson 1 of 4 Tutorial
0/4 completed

JavaScript Basics

Variables

Use let and const to store data:

let name = "Alice";       // can change later
const age = 25;           // cannot change
let score = 0;            // number

Data Types

TypeExample
String"Hello"
Number42, 3.14
Booleantrue, false
Array[1, 2, 3]
Object{name: "Alice", age: 25}

Operators

let sum = 5 + 3;       // 8
let diff = 10 - 4;     // 6
let product = 3 * 7;   // 21
let quotient = 15 / 3; // 5
let remainder = 7 % 3; // 1

Example

// Variables and data types
let studentName = "Amina";
const school = "King's College";
let grade = 95;
let isPassed = grade >= 50;

console.log("Student: " + studentName);
console.log("School: " + school);
console.log("Grade: " + grade);
console.log("Passed: " + isPassed);

// Arrays
let subjects = ["Math", "English", "Science", "Hausa"];
console.log("Subjects: " + subjects.join(", "));
console.log("Number of subjects: " + subjects.length);

Exercises

Exercise 1. Greet a Variable Easy
Create a variable name with the value "Ada" and log exactly: Hello, Ada!
Use a template literal: console.log(`Hello, ${name}!`)
// your code here
Expected Output
Hello, Ada!

Lesson Nav

Lesson sections