InfoparkDailyCAREER TOOLS

JavaScript · Lesson 5 of 8

Functions

Declaring functions, parameters, return values and arrow functions.

Functions are reusable blocks of code.

function greet(name) {
  return "Hello, " + name;
}
const add = (a, b) => a + b;   // arrow function
  • Parameters are the inputs; return sends a value back.
  • Default values: function hi(name = "friend").
  • A function without return gives undefined.
  • Variables declared inside a function are only visible inside it (scope).

Try it yourself

Edit the code and press Run (or Ctrl/⌘ + Enter). Code runs only in your browser, in a sandbox.

Key points

  • return gives a value back.
  • Arrow functions are a short syntax.
  • Defaults handle missing arguments.

Quick check

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

Practice task

Write a function that takes an array of salaries and returns the highest one, without using Math.max.

Interview corner

Function declaration vs arrow function?

Declarations are hoisted and have their own this. Arrow functions are shorter and take this from the surrounding scope — handy for callbacks.

What is a closure?

A function that remembers variables from the scope where it was created, even after that scope has finished running.

Further reading

Official documentation, linked for deeper study. These are outside sites; this lesson's text is our own.

Original lesson written by the InfoparkDaily team · © 2026 InfoparkDaily · Free to learn — no paid course or subscription.