Procedures

Let’s learn about procedures in JavaScript.

What are procedures?

Generally, a parametrized procedure is like a subprogram that can be called with a certain number of arguments any number of times from within a program. Whenever a procedure returns a value, it’s called a function. In OOP, procedures are called methods if they’re defined in the context of a class or an object.

In JavaScript, procedures are called functions, whether they return a value or not. JavaScript functions are special JS objects that have an optional name property and a length property that provide a number of parameters. Whether or not a v variable references a function can be tested as follows:

Press + to interact
var v = function () { console.log("I am a function.") }
if (typeof v === "function") {
console.log("true");
}
else {
console.log("false");
}

A JS object implies that JS functions can be stored in variables, passed as arguments to functions, returned by functions, have properties, and can be changed dynamically. Therefore, JavaScript functions are first-class citizens, and JavaScript can be viewed as a functional programming language.

The general form of a JS function definition is an assignment of a JS function expression to a variable.

var myMethod =
...