Javascript Syntax


Now that you know what JavaScript is and how to include it in a webpage, it's time to learn how to write it.

This lesson covers variables, data types, arrays, objects, and functions — the core building blocks you'll use in every D3 chart. Packed with interactive examples and exercises.

Members only
4 minutes read

📦 Variables: const and let

Like most programming languages, JavaScript stores values in variables. You'll use two keywords to create them:

  • const — creates a variable that cannot be reassigned. Use this by default.
  • let — creates a variable that can be reassigned. Use it only when you need to change the value later.
You might see var in older code. It's the legacy way of declaring variables — don't use it.
// const = constant, cannot be reassigned
const name = "Alice";
console.log(name);

// let = can be reassigned
let score = 10;
console.log(score);

score = 20;  // ✅ This works
console.log(score);

// name = "Bob";  // ❌ This would throw an error!

Note: the sandbox above shows code on the left and output on the right. The output panel is called the console — we cover it in the Developer Tools lesson.

Oh no! 😱

This lesson is not ready yet.

But we're working hard on it, releasing 1-2 lessons per week. If you're a student, check the discord channel for announcements! (discord logo logo above. )

🙇