Values and variables
Name data with const and let, and work with JavaScript’s basic value types.
- Create variables with const and let
- Distinguish strings, numbers and booleans
- Convert text input to a number
A variable gives a name to a value. Use const when you will not assign a different value later, and let when you will. Prefer const by default.
1const language = "JavaScript";
2let year = 1995;
3const isFun = true;
4
5console.log(language, year, isFun);JavaScript 1995 true
JavaScript has strings, numbers and booleans (true or false). The exercise input arrives as text, so convert it with Number(input) before doing arithmetic.
Key takeaways
Use
constby default andletfor reassigned values.JavaScript distinguishes strings, numbers and booleans.
Convert text to a number with
Number(value).
Lesson quiz
5 questions · pass with 4 correct · up to 50 XP
Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.
Practice: write JavaScript
Write the program, run it against the test cases, and use the feedback to build your JavaScript skills.
Price with tax
Read a price from input, add 8% tax, and print the total with two decimal places.
- $10 purchase
- $25 purchase
JavaScript runs in a sandboxed browser frame with a 1.5 second time limit. Input is available as the string variable input.
Questions about this lesson
Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.
Loading posts…