Revised Function.toString() Method

Function.toString() converts a function to a string representation, revealing its source code, including comments and formatting, facilitating debugging and dynamic code generation in JavaScript.

Syntax:

let result = myFunction.toString();

Example: Here the basic example of above mentioned method.

Javascript




function myFunction(name) {
    return `Hello, Geeks!`;
}
  
let result = myFunction.toString();
console.log(result);


Output

function myFunction(name) {
    return `Hello, Geeks!`;
}

Supported browser:

  • Chrome 1
  • Edge 12
  • Firefox 1
  • Safari 1
  • Opera 3


JS 2019 – ECMAScript 2019

ECMAScript 2019, also known as ES10, introduced features like Array.flat(), Array.flatMap(), Object.fromEntries(), and Symbol. description, and some string methods, for enhancing JavaScript’s capabilities and expressiveness.

JavaScript 2019 (ES10) or ECMAScript 2019 new features are:

Name

Description

String.trimStart()

trimming leading whitespace characters from a string.

String.trimEnd()

removes trailing whitespace characters from the end of a string

Object.fromEntries

Creates an object from a key-value pairs array.

Optional catch binding

omitting the catch parameter in try-catch blocks, simplifying error handling

Array.flat()

flattening nested arrays to a single-dimensional array.

Array.flatMap()

mapping and flattening nested arrays simultaneously for streamlined operations.

Revised Array.Sort()

Equal value elements retain relative positions during sorting.

Revised JSON.stringify()

safely handles UTF-8 code points (U+D800 to U+DFFF) accurate compatibility with JSON.parse().

Separator symbols allowed in string litterals

separator symbols are allowed within numeric and string literals to improve readability without affecting their values

Revised Function.toString()

converts a function to a string representation

We will explore all the above methods along with their basic implementation with the help of examples.

Similar Reads

Method 1: String.trimStart() Method

This method is used to trims leading whitespace characters from the beginning of a string, enhancing JavaScript’s string manipulation capabilities for improved data handling and formatting....

Method 2: String.trimEnd() Method

...

Method 3: Object.fromEntries() Method

This method is used to removes trailing whitespace characters from the end of a string, offering enhanced string manipulation capabilities for improved data handling and formatting in JavaScript....

Method 4: Optional catch Binding

...

Method 5: Array.flat() Method

Object.fromEntries() converts an array of key-value pairs into an object, simplifying object creation from structured data in JavaScript....

Method 6: Array.flatMap() Method

...

Method 7: Revised Array.Sort() Method

Optional catch binding in ECMAScript 2019 allows omitting the catch parameter in try-catch blocks, simplifying error handling when the caught error object isn’t needed....

Method 8: Revised JSON.stringify() Method

...

Method 9: Separator Symbols Allowed in String Litterals

Array.flat() method collapses nested arrays within an array to a single-dimensional array, simplifying array manipulation and enhancing data processing in JavaScript....

Method 10: Revised Function.toString() Method

...