What is the difference between custom and built-in functions in JavaScript?


The custom functions in JavaScript are user-defined functions. JavaScript allows us to write our own functions. The following is the syntax −

Syntax

<script>
   <!--
      function functionname(parameter-list)
      {
         statements
      }
   //-->
</script>

Bult-in functions are functions already provided by JavaScript library, for example, the following are string functions −

S. No
Method & Description
1
charAt()
Returns the character at the specified index.
2
charCodeAt()
Returns a number indicating the Unicode value of the character at the given index.
3
concat()
Combines the text of two strings and returns a new string.
4
indexOf()
Returns the index within the calling String object of the first occurrence of the specified value, or -1 if not found.

Example

The following is an example of a built-in function in JavaScript to concatenate strings −

 Live Demo

<html>
   <head>
      <title>JavaScript String concat() Method</title>
   </head>
   
   <body>
      <script>
         var str1 = new String( "This is string one" );
         var str2 = new String( "This is string two" );
         var str3 = str1.concat( str2 );
         
         document.write("Concatenated String :" + str3);
      </script>
   </body>
</html>

Output

Updated on: 23-Jun-2020

426 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements