Concept Flow - Output formatting basics
Start
Prepare data
Choose format method
Apply formatting
Print or return formatted output
End
This flow shows how data is prepared, formatted, and then output in JavaScript.
const name = "Alice"; const age = 30; console.log(`Name: ${name}, Age: ${age}`);
| Step | Action | Evaluation | Result |
|---|---|---|---|
| 1 | Declare variable name | name = "Alice" | name holds "Alice" |
| 2 | Declare variable age | age = 30 | age holds 30 |
| 3 | Format string with template literal | `Name: ${name}, Age: ${age}` | "Name: Alice, Age: 30" |
| 4 | Print formatted string | console.log output | Name: Alice, Age: 30 |
| 5 | End of code | No more statements | Execution stops |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| name | undefined | "Alice" | "Alice" | "Alice" |
| age | undefined | undefined | 30 | 30 |
Output formatting basics in JavaScript:
- Use backticks (`) for template literals.
- Embed variables with ${variable} inside strings.
- Use console.log() to print formatted output.
- Single/double quotes do not substitute variables.
- Template literals make output readable and dynamic.name inside a string using template literals in JavaScript?const count = 3;
console.log(`You have ${count} new messages.`);
count inside ${} is replaced by its value 3.let user = 'Anna';
console.log('Welcome, ${user}!');
name = 'Sam' and age = 25. Which code correctly formats the output as: Hello, Sam! You are 25 years old.name and age inside the string.Pass the test and this pattern moves unknown