Page 77 - DCAP202_Fundamentals of Web Programming
P. 77

Fundamentals of Web Programming




                    Notes          Strings are called constants or literals. The string value  “hello” is called a  string constant  or
                                   literal. To change a string requires replacing it with another string.
                                   Strings can contain escape sequences (a single character preceded with a backslash), as shown in
                                   Table 6.2. Escape sequences are a mechanism for quoting a single character.
                                                              Table  6.2: Escape  Sequences


                                       Escape Sequence                    What It Represents
                                     \'                Single quotation mark
                                     \"                Double quotation mark
                                     \t                Tab
                                     \n                Newline
                                     \r                Return
                                     \f                Form feed
                                     \b                Backspace
                                     \e                Escape
                                     \\                Backslash
                                     Special Escape Sequences
                                     \XXX              The character with the Latin-1 encoding specified by up to three
                                                       octal digits XXX between 0 and 377. \251 is the octal sequence for
                                                       the copyright symbol.
                                     \xXX              The character with the Latin-1 encoding specified by the two
                                                       hexadecimal digits XX between 00 and FF. \xA9 is the
                                                       hexadecimal sequence for the copyright symbol.
                                     \uXXXX            The Unicode character specified by the four hexadecimal digits
                                                       XXXX. \u00A9 is the Unicode sequence for the copyright symbol.


                                          Example: Illustrating strings in java script
                                     <html>
                                     <head>
                                     <body>
                                     <pre>
                                     <font  size=”+2">
                                     <script  language=”JavaScript”>
                                     <!—  Hide  script  from  old  browsers.
                                     document.write(“\t\tHello\nworld!\n”);
                                     document.writeln(“\”Nice  day,  Mate.\”\n”);
                                     document.writeln(‘Smiley  face:<font  size=”+3">  \u263a\n’);
                                     //End  hiding  here.  —>
                                     </script>
                                     </pre>
                                     </body>
                                     </html>
                                   Output
                                     Hello




          70                                LOVELY PROFESSIONAL UNIVERSITY
   72   73   74   75   76   77   78   79   80   81   82