How built in Functions in Java Script work?

How built in Functions in Java Script work?

Every programming language has special lines of codes that perform a specific task that is assigned to them & this block starts execution when it is called. We all know that, though JavaScript is used for web technologies, it is a programming language that works with functions as well. Unlike other programming languages, JavaScript contains in-built functions which can be called & used as per the requirement.

In JavaScript, there are different functions for different uses. Like to perform some mathematical operations you use Maths class JavaScript functions, to perform some string operations you can use string class JavaScript functions.

There are the following JavaScript in-built functions are available which you can use as per the requirement:

● Number Functions

● Boolean Functions

● String Functions

● String HTML wrappers

● Array Functions

● Date Functions

● Math Functions

● RegExp Functions

Number Functions

These are the in-built JavaScript functions used to perform the operations on every object.

There are the following functions available in the Number


It returns the function that creates an object instance. It means that whenever we create an object in JavaScript, constructors get called. By default it is a number object.

Syntax : var.constructor();

Result: a function name which has created a variable instance.


This function forces a number to display exponential notation, normally JavaScript uses a standard notation. This function can be called as

Syntax : number.toExponential(FractionDigits);

Result: Number with limited FractionDigits after decimal point & exponent.


This function displays the specific numbers after the decimal point.

Syntax : number.toFixed(Digits);Result: Number with mentioned number of Digits after decimal point.


It returns a string value of the current number, a string value format that depends on the browser's current location setting.

Syntax : number.toLocaleString();

Result: Only number.


This function defines how many digits have to be displayed on both sides of the decimal point.

Syntax : number.toPrecision(2).

Result: only 2 numbers regardless of decimal point.


Returns the String value of the number value.

Syntax : number.toString();

Result: String representation of a number.


Returns the number's value.

Syntax : valueOf(var);

Result: number stored in the var variable.

Boolean Functions

In a programming language, boolean value means either true or false or 0 or 1.

Using these Functions, you can make a decision to run forward code or not.


Return a string containing a source of boolean object.

Syntax : var.toSource();

Result : return the values stored in the variable.


Returns a string "true" or "false" depending upon the object.

Syntax : var.toString();

Result : true or false.


Return a value of boolean object

Syntax :var.valueOf();

Result : value stored in variable var.

String Functions

In programming language, string is a set of characters or simply it is a sentence which has characters. String is represented in " ". Following are the available functions in the String.


Returns a character located in a specific position.

Syntax : str.charAt(3);

Result : character located in 3rd position.

Here, string position starts from 0.


Returns an assembly value of a character located in a specific position.

Syntax : str.charCodeAt(3);

Result : assembly value of character located in 3rd position.


Join 2 strings together to form a 1 string.

Syntax : str1.concat(str2);

Result : str1+str2


Returns a position of a specific character.

Syntax : str.indexOf(‘a’);

Result : position of a char ‘a’ in number format.


Returns a position of a last occurrence of a specific character.

Syntax : str.lastIndexOf(‘a’);

Result : last occurrence position of a char ‘a’ in number format.


Returns a number which shows whether a given string comes before or after or is the given string same as the stored one.

Syntax : str.localeCompare(‘a’);

Result : -1 : if given string comes after source string.

1: if the given string comes before the source string.

0 : if the given string is the same as the source string.


Calculate the length of the string or number of characters & spaces in the string.

Syntax : str.length();

Result : number of characters in addition with spaces.


Matches string with given regular expression.

Syntax : str.match(‘regular expression’);

Result : Returns a matched string.

9. replace()

Find a matched string with regular expression & replace it by a given string.

Syntax : str.replace(‘regex’, ‘string for replacement’);

Result : String with replacement string added.

Returns a match between regex & given string.

Syntax : str. search(‘string’);

Result : -1 : if the given string is not present in the source string.

1: if the given string is present the source string.

0 : if the given string is the same as the source string.


Cut the section of the string & return a new string.


Forms a string object into an array of string & represents each array element as a substring.


Returns a small part of string with the given starting position upto given number of characters.


Returns a small part of the string with a given starting and ending position.


Converts string characters in lowercase.


Converts string characters in uppercase.


Returns a string representation of any object.


Returns a value of specified object.

HTML wrappers

These functions are used to execute HTML code in JavaScript code. If we want to execute any HTML tag we can use these functions.

1.anchor() To create an HTML anchor tag same as Syntax str.anchor(anchorname);

2.big()   To display a string in big font same as HTML  tag.Syntax - str.big();

3.bold()  To display a string in bold the same as HTML  tag.Syntax - str.bold();

4.fontcolor()  To display a string in the given color same as HTML <fontcolor =”color”> tag.

Syntax - str.fontcolor(“red”);

5. fontsize()  To display a string in the given font size same as HTML <fontsize = “size”> tag.

Syntax - str.fontsize(“20px”);

6.italics()  To display a string in italic format same as HTML tag.

Syntax - str.italics();  To create a Hypertext link that requests another URL.

Syntax - name);

8.small()  To display a string in small font same as HTML  tag.

Syntax - str.small();

9.sub()  To display a string as a subscript same as HTML tag.

Syntax - str.sub();

10.sup()  To display a string as a superscript same as HTML  tag.

Syntax - str.sup();

Array Functions

Array is nothing but the set of elements which represents the same type. Like you can create an array of numbers, characters or string values.There are following array functions available which you can use as per therequirement.

1.concat(): To join 2 arrays & display as a 1 array.

Syntax - arr1.concat(arr2);

2.every():  Returns true if every element in the array satisfies the given

Syntax - arr1.every(callback[, thisObject]);

3.filter():  Returns an array with source array elements by applying a filter.

Syntax - arr1.filter(callback[, thisObject]);

4.forEach(): Calls a specific function for each element in the array.

Syntax - arr1.forEach(callback[, thisObject]);

5.indexOf():  Returns a numbered value for the given array element.

Syntax - arr1.indexOf(searchElement[, thisObject]);

6.join():  Join all the elements in the array to form a string.

Syntax - arr1.join(separator);

7.lastIndexOf():  Returns a numbered value of the last occurrence of the given array element.

Syntax - arr1.lastIndexOf(searchElement[, fromIndex]);

8. pop():  Removes a given array element from the source array.

Syntax - arr1.pop(element);

9.push(): Adds a given array element to the source array.

Syntax - arr1.push(element);

10.reverse(): Reverse the source array elements.

Syntax - arr1.reverse();

11.shift():  Removes the first element of the array and returns that element.
Syntax - arr1.shift();

12.toString(): Converts array elements into string.

Syntax - arr1.toString();

Date Functions

A Date object in the JavaScript contains a Date, Time & Timezone. You can work with this Date object to get & set time, date & timezone.

1.Date():  Returns today’s date & time.

Syntax - var d1 = Date();

2.getDate():  Returns date according to the locale time.

Syntax - var ans =d1.getDate();

3.getDay():  Returns a day of the week according to the locale time.

Syntax - var ans =d1.getDay();

4.getFullYear(): Returns a year of the specified date.

Syntax - var ans =d1.getFullYear();

5.getMonth():  Returns month according to local Date.

6.getHours():  Returns hours according to local time.

Syntax - var ans =d1.getHours();

7.getMilliSeconds():  Returns milliseconds according to local time.

8.getMinutes():  Returns minutes according to local time.

9.getSeconds():  Returns seconds according to local time.

10.getTime():  Returns a time according to the local timezone.

11.getTimezoneOffset(): Returns timezone offset in minutes for current local time.

12.setDate():  Set a day of the month for a specified date according to locale time.

Syntax - var ans =d1.setDate(14);

13.setFullYear():  set a full year for a specified date according to locale time.

14.setDay():  set a day of the week for a specified date according to locale time.

15.setMonth(): set a month for a specified date according to locale time.

16.setHours(): set hours for a specified date according to locale time.

17.setMilliSeconds(): set milliseconds for a specified date according to locale

18.setMinutes():  set minutes for a specified date according to locale time.

19.setSeconds():  set seconds for a specified date according to locale time.

20.setTime():  set the date object to the time represented by the number of milliseconds since Jan 1, 1970, 00:00:00 UTC.

21.toString():  Converts a date into string representation.

22.toTimeString():  Returns a Date part of the date as a readable string.

23.valueOf(): Returns a primitive value of a Date object.

Math Functions

JavaScript has in-built Math functions which are very useful to perform math
operations on the object.

1.abs()   Returns an absolute value of the number.

Syntax - var val = Math.abs();

2.ceil()  Returns a smallest integer or an integer equal to a given number.

Syntax - var val = Math.ceil(45.67);

3.exp()   Returns E^N, where N is the argument & E is the euler’s constant, a base of the natural logarithm.

Syntax - var val = Math.exp(23);

4.floor():  Returns a largest integer less than or equal to a given number.

5.log():  Returns a logarithmic value of a given number with a base E.

6.max():  Returns a maximum value between the given numbers.

Syntax - var val = Math.max(34,78);

7.min():  Returns a minimum value between the given numbers

8.pow():  Returns a factorial value of the given number.

9.random():  Return a random value between the given range of numbers.

10.round():  Returns a round figure of the given decimal number.

11.sqrt():  Returns a square root of the given number.

12.cos(): Returns a cosine of the number.

13.sin():  Returns a sine value of the number.

14.tan():  Returns a tan value of the number.

RegExp Functions

Regex is the string format or a pattern string which is used to validate a given

1.exec():  executes a search for a match in source string parameter

Syntax - RegExpObject.exec(string);

2.test(): Tests for a match in the given string parameter.

Syntax - RegExpObject.test(string);

The above listed functions are the JavaScript in-built functions, which can be used
while programming as per requirement. It mostly used to enhance the functionality of your website.

You've successfully subscribed to HTML5Awesome
Great! Next, complete checkout to get full access to all premium content.
Welcome back! You've successfully signed in.
Unable to sign you in. Please try again.
Success! Your account is fully activated, you now have access to all content.
Error! Stripe checkout failed.
Success! Your billing info is updated.
Billing info update failed.