Fonction JavaScript toString ()

La méthode JavaScript Function toString () renvoie le code source de la fonction sous forme de chaîne.

La syntaxe de la toString()méthode est:

 func.toString()

Voici funcune fonction.

Paramètres toString ()

La toString()méthode ne prend aucun paramètre.

Valeur renvoyée par toString ()

  • Renvoie une chaîne représentant le code source de la fonction.

Exemple: utilisation de toString ()

 function f() () console.log(f.toString()); // function f() () function sum(a, b) ( return a + b; ) console.log(sum.toString()); // function sum(a, b) ( // return a + b; // ) // built-in functions console.log(console.log); // log() ( (native code) ) console.log(Function.prototype.toString); // toString() ( (native code) ) console.log((() => "Hello World!").toString()); // () => "Hello World!"

Production

 function f () () function sum (a, b) (return a + b;) log () ((code natif)) toString () ((code natif)) () => "Hello World!"

Lecture recommandée: JavaScript Object toString ()

Articles intéressants...