Last session of 2024

Introduction

What are let and const ?

Now that we have let and const, should we still use var?

Here are some things to think about so you can decide for yourself.

const | part 1

See the Pen HTML cheatsheet 1 / display types by perpetual.education (@perpetual-education) on CodePen.

Some people approach this var, let, const thing with a simple rule: “Just always use const, and if you can’t – then use let. And don’t ever use var.” But we’ve found that rules like this usually lead to gaps in understanding. So, just take a little time to think it through. Find some real-world use cases and try them out for yourself.

const | part 2

See the Pen HTML cheatsheet 1 / display types by perpetual.education (@perpetual-education) on CodePen.

A lot of people want to think of a variable as a box that holds a value. (and of course we’ve talked about this before…)

But remember how it works:

  1. A value is stored at some address in memory (pretend a:1)
  2. A reference is created (a “variable”) (but wouldn’t just calling it a reference be better…)
  3. The reference is pointed to the place in memory ( reference → a:1 )

Now when you reference the reference (the variable) (maybe that’s why they couldn’t call it that) – you’ll be pointing to that value stored at its associated address in memory.

Using the const keyword to assign a variable means it’s tied to that place in memory and can’t be pointed to another. It does not mean you can’t change things about a value stored there

let | part 1

See the Pen HTML cheatsheet 1 / display types by perpetual.education (@perpetual-education) on CodePen.

Get some tea and really spend some time looking at this in detail.

But also, don’t stress about it. You are totally fine to use var until we find some real-world situations that will help you learn about the differences. Just keep making stuff!

Last session of 2024