30 Days Of JavaScript

Day 1: Simple Types

Lesson 3: Variables

Constants are great but they are pretty inflexible, once you set it that's it forever.

Variables are the more flexible sibling to constants. You can create a variable, set it to a value and then later change that value to something new.

1let greeting = "hello";
2console.log(greeting);
3
4greeting = "hello world";
5console.log(greeting);

In the code above, we create a variable with the let keyword called greeting and set it to hello. We then log it out, change it to hello world and log it out again.

The first log will be hello and the second hello world. Note that when we change it to hello world we don't use the let keyword again. We only use let when we create the variable, if you were to put let in again you would get an error like: SyntaxError: Identifier 'greeting' has already been declared

Outline

Go Pro?

If you upgraded to pro, sign in here

  • About
  • Blog
  • Privacy
Looking to email me? You can get me on my first name at allthecode.co