JS Built-ins
FunctionFunctionbeginner

Function() β€” execute body from string

πŸ“– Usage Example
new Function('x', 'return x * 2') instanceof Function  // β†’ true

Dynamically created functions are instances of Function just like regular functions.

Function constructor β€” body string

Pass a single body string to new Function() to create a zero-argument function. Calling it executes the body.

Challenge: Verify that new Function('return 42')() returns 42.

πŸ’‘ Hints (2)
  • β€’ `new Function(body)` creates a function with that body.
  • β€’ Call it immediately with `()` to execute it.