Page 189 - Web Applications (803) Class 12
P. 189

eval( )                       A JavaScript expression is passed as a  eval(“5*4”)
                                                   string argument to this Method. After  Output: 20
                                                   that, eval( ) evaluates the expression
                                                   and  returns the result. It returns
                                                   undefined if no result is received.
                     Unary operator ‘+’            Converts string to number            + “24”
                                                                                        Output: 24

                 Other special functions include:

                      Output: true                       Description                               Example
                    isNaN( )          “Not-a-Number” is referred to as NaN in JavaScript.  isNaN(“Me”)
                                      In cases where a value is NaN, the isNaN() method  Output: true
                                      returns true.
                                      The  value  is converted  to  a  number  before  being   isNaN(1/5)
                                      tested by the isNaN() method.                       Output: false

                    isFinite( )       A  number  representing  positive  infinity  is  called
                                      infinity. -Infinity stands for the opposite of infinity.
                                      When a number exceeds its maximum value, it enters
                                      infinity:
                                      1.797693134862315E+308.
                                      When an integer crosses its lower bound, it enters
                                      infinity:
                                      -1.797693134862316E+308.
                                      If  a  value  is  a  finite  number,  the  isFinite()  method   Number.isFinite(“27”)
                                      gives a true result.                                Output: false
                                      Infinity,  -Infinity,  and  NaN  are  examples  of  infinite   Number.isFinite(653)
                                      (not finite) values.                                Output: true


                   3.6 STRINGS

                 In JavaScript, strings are collections of characters. They are actually collections of Unicode characters, each
                 of which is represented by a 16-bit number. We only need to use a string of length 1 to represent a single
                 character.























                                                                                          Web Scripting—JavaScript   187
   184   185   186   187   188   189   190   191   192   193   194