JS: Function.prototype.toString

By Xah Lee. Date: .

f.toString ( )

Return a string representation of the function f.

The returned result may not be exactly the same between browsers or other JavaScript implementation.

function f () { return 3; }
console.log ( f.toString () === "function f() { return 3; }" ); // true
const ff = (x => 3);
console.log ( ff.toString () === "x => 3" ); // true
console.log ( Array.toString () );
// function Array() { [native code] }

console.log ( Function.toString () );
// function Function() { [native code] }

console.log ( Object.toString () );
// function Object() { [native code] }

console.log ( Array.prototype.pop.toString () );
// function pop() { [native code] }

Reference

ECMAScript 2015 §Fundamental Objects#sec-function.prototype.tostring

JS Function

  1. Define Function
  2. Arrow Function ⭐
  3. Function Params
  4. “arguments” Object
  5. Rest Params ⭐
  6. Arg Default Value ⭐
  7. Arg Destructure ⭐
  8. f Declaration vs Expression
  9. Closure
  10. f call apply bind
  11. Functional Programing
Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. Visual CSS
  3. JS in Depth
  4. JS Reference
  5. DOM
  6. SVG
  7. Web Dev Blog