Explain any two built in objects in JavaScript

Mumbai University > Information Technology > Sem 4 > Web Programming

Marks: 10M

Year: Dec 2014

1 Answer

1) Math Object:

  • To execute mathematical computations, there are some useful methods available from math object.
  • It supports various functions like to find out maximum number, minimum number, power, log, ceil and floor of any number.
  • For example:


    The above statement will find out maximum number among the numbers given.

  • Some of important functions are:

Method name Purpose
sqrt(num) To find out square root of a number
min(numbers) To find out minimum number from given numbers
max(numbers) To find out maximum number from given numbers
ceil(num) To find out ceil value of number eg. ceil(11.4) will return 12
floor(num) To find out floor value of number eg. floor(11.2) will return 11
pow(num, power to) To find out power of a number eg (3,3) will return 9
log(num) To find out log of a number
abs(num) To find out absolute value,of a number
sin(num) To find out sine of a number
cos(num) To find out cosine of a number
tan(num) To find out tangent of a number
exp(num) To find out exponential of a number


<head><title>Math object</title>
<script type=”text/javascript”>



2) String Object:

  • A string is a collection of characters. In javascript using string object, many useful string related functionalities can be exposed off.
  • Some commonly used string methods are concatenating strings, converting the string to upper case or lower case, finding a substring of a given string and many others.
  • One of the important property of string is length. This is used to find out length of a string.
  • For example:

    var string1=”Kt280”;

    ven len;

. len=string1.length;

  • len variable will have a value 5.
Method name Purpose
concat(str) To concatenate two strings
charAt(index_val) To return character at a specified index
Substring(begin,end) To find out substring specified at begin and end character
toLowerCase() To convert string into lower case
toUpperCase() To convert string into upper case
Valueof() To return value of the string

HTML File:

<head><title>String object</title>
<script type=”text/javascript”>
var s1=”alia”;
var s2=”Bhatt”;
document.write(“first string is:”+s1+”<br>”);
document.write(“second string is:”+s2+”<br>”);
document.write(‘Concatenating two strings;”+s1.concat(s2));
document.write(“length of first string is;”+s1.length);
document.write(“Character at 2nd position of second string is ” + s2.charAt(2));
document.write(“ Substring from second string:”+s2.(1,3)):


first string is:alia

second string is:bhatt

Concatenating two strings:aliabhatt

length of first string is:4

Character at 2nd position of second string is:h

Substring from second string:hat

Please log in to add an answer.