Skip to content
Guest
Learn JavaScript · Course Syllabus Show lessons
Language Foundations · 8 min read · Beginner

Functions, Conditionals & Template Literals

Write reusable arrow functions, make decisions with if/else and ternaries, and format dynamic strings with template literals.

What you'll learn

  • Define reusable arrow functions with parameters and return values
  • Branch logic cleanly using if/else and the ternary operator
  • Build readable dynamic strings with template literals

Functions let you package reusable logic so you don’t repeat yourself. Modern JavaScript favors arrow functions (const fn = (x) => ...) and template literals (backticks `Hello, ${name}`).

Clean Arrow Functions

const getGrade = (score) => {
  if (score >= 90) return 'A: Excellent!';
  if (score >= 75) return 'B: Solid work!';
  return 'Keep practicing!';
};

Try It Yourself

Move the score slider in the live preview and inspect how getGrade() evaluates in real time:

Live Grade Calculator
Live Result
Console Output

No console output yet. Try calling console.log(...) in JS.

Check Your Understanding

Score: 0 / 1

1. Which syntax correctly embeds a variable named user inside a JavaScript template literal?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind