← Back to Course

🔤 Strings and User Input

Programs often work with text from users, files, or interfaces. Strings and input handling are core parts of everyday coding.

String Basics

Example: Text Operations

const firstName = "James";
const lastName = "Smith";
const fullName = `${firstName} ${lastName}`;

console.log(fullName.toUpperCase());
console.log(fullName.length);

Why Input Needs Care

User input can be missing, empty, or in the wrong format. It often needs trimming, validation, or conversion before it is safe to use.

Example: Clean Up Input

const rawName = "   Mia   ";
const cleanedName = rawName.trim();

if (cleanedName.length > 0) {
  console.log(`Hello, ${cleanedName}`);
}
← Back to Code Foundations