Variables and values

Lesson 2 of 15 7 min read Free lesson

Store numbers and text in variables with let and const, and name them well.

Storing values

JavaScript Try it in CodeLab
const church = 'RCCG';
let members = 120;
members = members + 5;
console.log(church + ' has ' + members + ' members');
Output
RCCG has 125 members
KeywordUse it when
constThe value is never reassigned (use it by default)
letThe value will change later
varOld code only; avoid

Naming rules

  • Names can contain letters, digits, _ and $ but cannot start with a digit.
  • Use camelCase: firstName, totalScore.
  • Choose names that say what the value is: studentCount, not x.

Exercise

Store your name and age in variables, then print a sentence like "Ada is 17 years old."

Starting code Try it in CodeLab
// your variables here
Show a possible solution
Solution
const name = 'Ada';
let age = 17;
console.log(name + ' is ' + age + ' years old.');

Check your understanding

Quick check

Which keyword should you use for a value that never changes?

Quick check

Which is a valid variable name?

Quick check

What does camelCase look like?

Hi there! đź‘‹ Have a question about the courses or joining the class? Ask me.