Summary - Data types
- Node.js course
- Beginner
- Lesson 18/116
- 5 min
Combine primitive types, template literals and Math to write a calculation card.
Summary - Data types
In this group you saw data types: five primitives (number, string, boolean, null, undefined), embedding with template literals, Math functions, the unique Symbol and the typeof operator.
Now there are two tasks: one with template literals, one with typeof. First recall what you learned, then apply it.
Practice Print with a template literal
Declare const product = 'book' and const price = 25. Use a template literal to print product and price in one line; the output should be Item: book, Price: 25.
Starter code
const product = "book";
const price = 25;
// Print 'Item: ...' with a template literalSample solution
const product = "book";
const price = 25;
console.log(`Item: ${product}, Price: ${price}`);Expected output
Item: book, Price: 25
Practice Print multiple types with typeof
Declare let value = 42. Call console.log(typeof value); then reassign value = 'text' and call console.log(typeof value) again. Output should be two lines.
Starter code
// Declare value and log its type with typeof
// Then reassign value and log againSample solution
let value = 42;
console.log(typeof value);
value = "text";
console.log(typeof value);Expected output
number string
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Primitive reminder
____ 42 // returns 'number'
typeof 42 // returns 'number'
Explanation: typeof returns a value's type.
2 Match the type concepts
| Term | Meaning |
|---|---|
number |
Number type |
string |
String type |
boolean |
Logical type |
symbol |
Unique type |