Core programming fundamentals · Lesson 3 of 60 · Code lesson, JavaScript or Python · Optional
Variables and constants
A variable is a name for a value.
Once a value has a name, you can use the name wherever you would use the value.
A constant is a name whose value should never change, such as a tax rate.
Worked example
In JavaScript, const score = 7 gives the number 7 the name score and stops the name from being reassigned. Use let for a variable that will change.
const score = 7;
console.log(score);Output: 7
In Python, score = 7 gives the number 7 the name score. Python has no const, so names in ALL_CAPS, like MAX_SCORE, mark constants by habit.
score = 7
print(score)Output: 7
Your turn
Change the number stored in score to 12, then print the stored number.
Expected output: 12
Loading your practice…
Preparing your workspace…