JS: Function.prototype.toString

By Xah Lee. Date: . Last updated: .
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;
}
*/
const ff = (x) => 3;
console.log(ff.toString());
// (x) => 3
console.assert(
 Array.toString() ===
  "function Array() { [native code] }",
);
console.assert(
 Function.toString() ===
  "function Function() { [native code] }",
);
console.assert(
 Object.toString() ===
  "function Object() { [native code] }",
);
console.assert(
 Array.prototype.pop.toString() ===
  "function pop() { [native code] }",
);