0
0
Javascriptprogramming~5 mins

Output formatting basics in Javascript

Choose your learning style9 modes available
Introduction

Output formatting helps make information clear and easy to read when your program shows results.

Showing a message with numbers and words together
Displaying a list of items neatly
Printing dates or prices in a friendly way
Making output easy to understand for users
Syntax
Javascript
console.log(`Hello, ${name}!`);
console.log(`You have ${count} new messages.`);

Use backticks `` to create template strings for easy formatting.

Place variables inside ${} to insert their values.

Examples
Prints a greeting with the name included.
Javascript
const name = 'Alice';
console.log(`Hello, ${name}!`);
Shows a price with a dollar sign.
Javascript
const price = 9.99;
console.log(`Price: $${price}`);
Displays a message with a number inside text.
Javascript
const items = 3;
console.log(`You have ${items} items in your cart.`);
Sample Program

This program greets the user and tells how many new messages they have, using output formatting.

Javascript
const user = 'Bob';
const messages = 5;
console.log(`Hello, ${user}!`);
console.log(`You have ${messages} new messages.`);
OutputSuccess
Important Notes

Always use backticks `` for easy and readable output formatting.

You can combine text and variables smoothly with ${} inside template strings.

Summary

Output formatting makes program messages clear and friendly.

Use template strings with backticks and ${} to insert variables.

This helps users understand program results easily.