Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

Functions are Objects

The typeof operator in JavaScript returns “function” for functions.

However, JavaScript functions are essentially objects.

Functions in JavaScript have both properties and methods.

The arguments.length property returns the number of arguments passed when the function is invoked.

Example

function myFunction(a, b) {
  return arguments.length;
}

The toString() method returns the function as a string representation.

Example

function myFunction(a, b) {
  return a * b;
}

let text = myFunction.toString();
A function defined as a property of an object is called a method of that object.
A function designed to create new objects is called an object constructor.