0Pricing
JavaScript Academy · Lesson

Template Literals & Common String Operations

Use template literals and essential string methods; quick tour of numbers and Date basics.

Template Literals & Common String Operations is a free JavaScript Academy lesson on CoddyKit — lesson 1 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the JavaScript Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Intro

Goal: Format text with template literals and use simple string methods. Then see a quick intro to numbers and dates.

  • Template literals
  • Common string ops
  • Safe rounding
  • Date basics
Template Literals & Common String Operations — illustration 1

Template literals basics

Use backticks and ${} to insert values directly. Multi-line text is easy too.

// Template literals use backticks and ${}
// They support variables, expressions, and multi-line text
const name = "Ayla";
const score = 7;
const msg = `Hello, ${name}! Your score is ${score * 10}.`;

console.log(msg);

const lines = `Line 1
Line 2`;
console.log(lines);
Template Literals & Common String Operations — illustration 2

String methods tour

Practice length, trim, toUpperCase, includes, indexOf, slice.

// Common string methods on a small example
const title = "  JavaScript Basics  ";

console.log("Length:", title.length);
console.log("Trim:", title.trim());
console.log("Upper:", title.toUpperCase());
console.log("Includes JS:", title.includes("JavaScript"));
console.log("Index of B:", title.indexOf("B"));
console.log("Slice 2..6:", title.slice(2, 6));
Template Literals & Common String Operations — illustration 3

Concise formatting

Templates are shorter and easier to read than long + chains.

// Concatenation with + versus template literals
const user = "Mina";
const points = 12;

const viaPlus = "User: " + user + ", Points: " + points;
const viaTpl = `User: ${user}, Points: ${points}`;

console.log(viaPlus);
console.log(viaTpl);
Template Literals & Common String Operations — illustration 4

Rounding basics

Use Math.round, floor, ceil for integers. toFixed returns a string with a fixed number of decimals.

// Numbers: integers, floats, and rounding helpers
const price = 4.35;
const qty = 3;

const total = price * qty;
console.log("Total raw:", total);

console.log("Math.round:", Math.round(total));
console.log("Math.floor:", Math.floor(total));
console.log("Math.ceil:", Math.ceil(total));

// toFixed returns a string with fixed decimals
console.log("toFixed(2):", total.toFixed(2));
Template Literals & Common String Operations — illustration 5

Date quick tour

Create a Date with new Date(). Read parts with getters and print ISO for a standard format.

// Date basics: now, parts, and ISO output
const now = new Date();

console.log("Now:", now.toString());
console.log("Year:", now.getFullYear());
console.log("ISO:", now.toISOString());
Template Literals & Common String Operations — illustration 6

Template literal quiz

Quick check: Backticks and ${}.

Template Literals & Common String Operations — illustration 7

Recap

Recap: You used template literals, practiced key string methods, rounded numbers safely, and created/printed dates.

Template Literals & Common String Operations — illustration 8

Frequently asked questions

Is the “Template Literals & Common String Operations” lesson free?

Yes — the full text of “Template Literals & Common String Operations” is free to read here on the web, and the JavaScript Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the JavaScript Academy course, upgrade to CoddyKit PRO.

What will I learn in “Template Literals & Common String Operations”?

Use template literals and essential string methods; quick tour of numbers and Date basics. You practise JavaScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start JavaScript Academy?

No prior experience is required. JavaScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 3, so you can start here or from the beginning and move at your own pace.

How long does the “Template Literals & Common String Operations” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this JavaScript Academy lesson?

Yes. Every JavaScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Template Literals & Common String Operations
  2. Numbers — Integers vs Floats & Math Essentials
  3. Dates — Basics, Time Zones, Intl.DateTimeFormat
← Back to JavaScript Academy