Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

The Function() Constructor

As shown in the previous examples, JavaScript functions are defined using the function keyword.

Functions can also be defined using the built-in JavaScript Function() constructor.

Example

const myFunction = new Function(“a”“b”“return a * b”);

let x = myFunction(43);

You don’t necessarily need to use the function constructor. The example above is equivalent to writing:

Example

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

let x = myFunction(43);

In most cases, you can avoid using the new keyword in JavaScript.