C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Function toString() methodThe JavaScript Function toString() method returns a string. Here, string represents the source code of the function. Syntaxfunction.toString() Return ValueIt returns a string. JavaScript Function toString() method ExampleExample 1Let's see an example to display a function in the form of string. <script> function add(a,b) { return a + b; } document.writeln(add.toString()); document.writeln(typeof add.toString()); </script> Output: "function add(a,b) { return a + b; }" "string" Example 2Let's see an example to display the addition of numbers in the form of string. <script> function add(a,b) { return a + b; } document.writeln(add(10,20).toString());//30 document.writeln(typeof add(10,20).toString());//string </script> Output: 30 string Example 3Let's see an example to display the ceil value of the given numbers in the form of string. <script> function absolute(num) { return Math.ceil(num); } document.writeln(absolute(15.4).toString()); document.writeln(typeof absolute(15.4).toString());</script> Output: 16 string
Next TopicJavaScript Function
|