noknow.dev
Sign inSign up
Course overview
JavaScript Fundamentals
0 / 7 lessons0%

Getting Started

  • Hello, World!
  • Variables: let and const
  • Numbers and Math

Decisions & Loops

  • if / else — Making Decisions
  • for Loops

Functions

  • Defining Functions
  • Arrow Functions

Variables: let and const

0m 00s

What are variables?

Variables are containers for values — you give a value a name so you can reuse it later.

let age = 25
console.log(age)   // 25
age = 26           // changing the value is allowed
console.log(age)   // 26

let vs. const

Use let when the value might change later.
Use const when the value should stay fixed:

const PI = 3.14159
PI = 3  // ❌ Error! const cannot be reassigned

const name = "Alice"
console.log("Hello,", name)  // Hello, Alice

Rule of thumb: Always use const, and switch to let only when you need to reassign the value.

Your task

Create two variables:

  • name with your name (or any name)
  • age with an age

Then print: My name is [name] and I am [age] years old.

Back
javascriptCtrl+Enter to run
Output

Click "Run" to execute your code.