Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Muuttujat ja vakiot | Osio
Javascriptin Perusteet

bookMuuttujat ja vakiot

Pyyhkäise näyttääksesi valikon

Variables let you store data that can change, while constants store values that should stay the same. Use:

  • let: when the value can change;
  • const: when the value should not change.
123456
let score = 10; score = 15; // value can change console.log(score); const maxPlayers = 4; // maxPlayers = 5; // ❌ error
copy

Best Practices

  • Use const by default;
  • Use let only when needed;

Naming Variables

Use clear and descriptive names:

let playerScore = 100;
let maxLevel = 10;

Avoid:

  • Starting with numbers;
  • Reserved words;
  • Unclear names like x or data.

Why This Matters

Variables are the foundation of everything in JavaScript. You'll use them to store user data, application state, and results.

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 3

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

Osio 1. Luku 3
some-alt