Page 348 - Webapplication11_C11_Flipbook
P. 348

Ð ÐvalueOf( ): It returns a string’s primitive value. The original string is not changed by the method.
                 For example:

                 <!DOCTYPE html>
                 <HTML>
                 <HEAD>
                     <TITLE> ValueOf function </TITLE>
                 </HEAD>
                 <BODY>
                     <H1> Using valueOf </H1>
                 <SCRIPT>

                     text = "I am studying JavaScript";
                     result = text.valueOf();
                    document.write(result);
                 </SCRIPT>
                 </SCRIPT>
                 </BODY>
                 </HTML>
              Output of the above code is as follows:














                 4.17 MATH OBJECT

              The JavaScript Math object offers a wide range of methods that are used to simplify mathematical calculations and
              speed up math-oriented programming. Here are a few:

                               Math.round(x)       Number x is rounded to its nearest integer
                               Math.ceil(x)        Number x is rounded up to its nearest integer

                               Math.floor(x)       Number x is rounded down to its nearest integer
                               Math.trunc(x)       Yields the integer part of the Number x

              Example:
                 <HTML>
                 <BODY>
                 <SCRIPT>
                 document.write(Math.round(7.4))

                 document.write("<br>"+Math.round(7.6))
                 document.write("<br>"+Math.ceil(3.9))
                 document.write("<br>"+Math.ceil(3.2))
                 document.write("<br>"+Math.ceil(-3.2))
                346     Touchpad Web Applications-XI
   343   344   345   346   347   348   349   350   351   352   353