Brief review of programming concepts: built-in functions

In the course of a program, it is often desirable to be able to modify data or create new values. Moreover, many of the same types of modifications may take place repeatedly. For this reason, there are both functions built into the programming language (allowing, for example, the addition of two numbers) as well as mechanisms for creating new functions. Here we focus on built-in functions provided by the programming language.

The action of a function can be characterized as the relationship between inputs to the function and the output produced (if any). A function consumes zero or more inputs (more formally, arguments) and produces zero or one output. Using a function might also result in a change to some data, which is known as a side effect.

An instruction to use a function on specific inputs is called a function call, in which we call the function on the inputs. For different functions there are different ways of expressing function calls, that is, different syntax.

There are several types of syntax that we will encounter. Don't worry if the meaning is not yet clear to you; you're not yet expected to know what the terms and notation mean.

  • Syntax for operations, such as 2 + 3, where the operator is placed between the inputs, or before or after a single input, such as i++.
  • Syntax for functions, such as alert("message"), where the name of the function is followed by parentheses, inside which are the input or inputs, separated by commas.
  • Syntax for methods, such as "message".indexOf("g"), where the input is followed by a period and then by the name of the function, with any further inputs in parentheses separated by commas. This is known as dot notation.

For convenience, we will refer to operations, functions, and methods all as functions. We will discuss methods in a later module on objects; you do not need to understand the term now. If you can recognize dot notation, that is enough for the moment.