Art 114: Interactive Media and Design

Spring 2025 | Harrisburg Area Community College

Instructor: Rich Hauck, MPS

JavaScript Variables

In JavaScript, variables are ways to hold different types of data in memory.

String

Represents text enclosed in quotes

const name = "John Doe"; 
const prefix = 'Mr. ';
const fullName = prefix + name;
const altFullName = `${prefix} ${name}`;

Number

let age = 25;
let count = -2342334.234242;

Boolean

let isDarkMode = true; 
let isRaining = 0;

Array

let fruits = ["apple", "banana", "orange"];
let rand = Math.round(Math.random() * 3) - 1; // Writing out to the page document.getElementById("header").innerText = fruits[rand];

Object

let person = { 
name: "John Doe",
age: 25,
isMarried: false
};