TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

JavaScript Function toString() Method

JavaScript Function toString() Method with example on javascript function object, javascript tutorial, apply(), bind(), call(), toString(), toSource(), isgenerator(), javascript handler, javascript reflect, object, number etc.

<< Back to JAVASCRIPT

JavaScript Function toString() method

The JavaScript Function toString() method returns a string. Here, string represents the source code of the function.

Syntax

function.toString()

Return Value

It returns a string.

JavaScript Function toString() method Example

Example 1

Let'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>
Test it Now

Output:

"function add(a,b) { return a + b; }" "string"

Example 2

Let'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>
Test it Now

Output:

30 string

Example 3

Let'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>
Test it Now

Output:

16 string





Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf