Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk3 min

JavaScript Variables and Data Types: A Clear Beginner’s Guide

A practical beginner’s guide to JavaScript declarations, scope, reassignment, primitive types, objects, dynamic typing, and typeof.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In JavaScript, a variable declaration creates a named binding, while a data type describes the value that binding currently holds. Use const when you do not need to reassign a binding, let when you do, and learn var mainly to understand older code and its different scope behavior.

What is a JavaScript variable?

A variable is a named binding that lets code refer to a value. In let score = 10;, score is the binding and 10 is its current value. The declaration keyword controls how the binding behaves; it does not permanently assign a type to the variable name.

As an Amazon Associate I earn from qualifying purchases.

JavaScript is dynamically typed: a binding can refer to values of different types at different times. The MDN JavaScript language overview explains this behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
let value = 42;
console.log(typeof value); // "number"
value = "hello";
console.log(typeof value); // "string"

typeof inspects the current value. Here, it returns "number" first and "string" after reassignment.

Should you use let, const, or var?

For ordinary modern JavaScript, prefer const unless the binding needs reassignment; use let for bindings that will be reassigned. Understand var because it appears in existing code, but its scope behavior can be surprising. The MDN language overview discourages using var in modern code.

Declaration Scope Reassignment Initialization Before initialization
let Block scope Allowed May be omitted; an unassigned binding evaluates to undefined Cannot be accessed before its initialization point
const Block scope Not allowed Required Cannot be accessed before its initialization point
var Associated with the surrounding variable environment; a block alone does not limit it Allowed May be omitted Different behavior from lexical declarations; its scope is not limited to a block

The ECMAScript 2026 specification says that “let and const declarations define variables that are scoped to the running execution context’s LexicalEnvironment.” See the ECMAScript 2026 declarations specification. In everyday terms, a block is a section of code enclosed in braces, and a block-scoped binding is visible only within that section.

Reassignment and mutation are different

Reassignment makes a binding refer to a different value. Mutation changes the contents of an object or array while the binding still refers to that same value. const prevents reassignment, not mutation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
let score = 10;
score = 11; // reassignment is allowed

const settings = { theme: "light" };
settings.theme = "dark"; // mutation is allowed
// settings = {}; // TypeError: reassignment is not allowed

The MDN const reference covers initialization, reassignment, and mutation of objects and arrays.

Block scope and the temporal dead zone

let and const bindings are not accessible before their declaration is initialized. That interval is called the temporal dead zone. By contrast, var is tied to the surrounding variable environment, so declaring it inside a block does not confine it to that block.

if (true) {
  let blockValue = "inside";
  var functionValue = "visible outside this block";
}

// blockValue is not available here
console.log(functionValue); // "visible outside this block"

What data types does JavaScript have?

ECMAScript defines seven primitive value types and the Object type. These categories describe values, not declaration keywords. The language categories are specified in ECMAScript 2024.

  • undefined: often the value of a declared binding that has not been assigned another value.
  • null: an intentional absence of an object value.
  • boolean: either true or false.
  • number: ordinary numeric values.
  • bigint: integer values for use cases beyond ordinary Number values.
  • string: text.
  • symbol: a unique symbol value.
  • object: structured values, including ordinary objects and arrays.

Arrays and functions are objects in JavaScript’s language model, even though they are often treated as separate practical categories when learning or building programs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How do you check a value’s type with typeof?

Use typeof to get a string describing the type category of a value in common cases. It reports the value at the time the expression runs, so call it again after reassignment if you want to inspect the new value.

const count = 500;
const label = "500";

console.log(typeof count); // "number"
console.log(typeof label); // "string"

The quotation marks make "500" text; it is not a number just because its characters are digits. MDN uses this distinction in its beginner material on variables and data types.

How should you choose a declaration?

  1. Start with const when you do not intend to make the binding refer to another value.
  2. Choose let when later code must assign a different value to that binding.
  3. When reading var, remember that a surrounding block does not limit its visibility in the way it does for let and const.
  4. Use typeof to inspect a value when needed, and remember that the type belongs to the value currently held, not permanently to the variable name.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.