Learn to Code
All tracks
Learn to Code

Free lessons from scratch to pro — every language, databases and DevOps.

AboutContactPrivacy PolicyTerms of Use

Your progress is saved in this browser. © 2026 Learn to Code

JS
JavaScript
0/12 completed
Beginner
What is JavaScript?Variables and data typesOperators and expressionsMaking decisions: if and switchLoops
Intermediate
FunctionsArrays and array methodsObjects
Advanced
Scope and closuresClasses and OOPPromises and async/await
Pro
The event loop
Tracks / JavaScript / Intermediate

Functions

A function is a reusable block of code with a name. You write it once and call it as many times as you like. Functions are the main way programmers organise code into small, understandable pieces.

Declaring and calling

JavaScript · editable
  • name is a parameter: a placeholder for the input.
  • 'Asha' is an argument: the actual value you pass in.
  • return sends a value back to whoever called the function. It also ends the function immediately.

A function without return gives back undefined.

Multiple parameters and defaults

JavaScript · editable

Arrow functions

Modern JavaScript has a shorter syntax called arrow functions. You'll see them everywhere.

JavaScript · editable

Functions are values

In JavaScript, you can store functions in variables, pass them to other functions, and return them. A function passed to another function is called a callback.

JavaScript · editable

This idea, higher-order functions, powers map, filter and much more in the next lesson.

Rest parameters

JavaScript · editable

Writing good functions

  • One job per function. If you need "and" to describe it, split it up.
  • Name it with a verb: calculateTotal, isValidEmail, fetchUser.
  • Prefer returning values over printing inside the function, so the result can be reused.

Practice

Write isPalindrome(word) that returns true if a word reads the same backwards, ignoring case. Hint: word.split('').reverse().join('') reverses a string.

JavaScript · editable
✎ Check your understanding

1.What does a function return if it has no return statement?

2.Which is a valid arrow function that doubles a number?

← Loops