O'Reilly logo

TypeScript Blueprints by Ivo Gabe de Wolff

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Functional programming

When you ask a developer what the definition of a function is, he would probably answer something like "something that does something with some arguments". Mathematicians have a formal definition for a function:

A function is a relation where an input has exactly one output.

This means that a function should always return the same output for the same input. Functional programming (FP) uses this mathematical definition. The following code would violate this definition:

let x = 1; 
function f(y: number) { 
  return x + y; 
} 
 
f(1); 
x = 2; 
f(1); 

The first call to f would return 2, but the second would return 3. This is caused by the assignment to x, which is called a side effect. A reassignment to a variable or a property is called ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required