Page 78 - DCAP202_Fundamentals of Web Programming
P. 78

Unit 6: Introduction to JavaScript




          world!                                                                                Notes
          “Nice  day,  Mate.”

          Smiley  face:  :&

          Explanation

          1.   The escape sequences will work only if in a <pre> tag or an alert dialog box.
          2.   The JavaScript program starts here.

          3.   The write() method sends to the browser a string containing two tabs (\t\t), Hello, a newline
               (\n), world!, and another newline (\n).
          4.   The writeln() method sends to the browser a string containing a double quote (\”), Nice day,
               Mate.,  another  double quote  (\”), and  a  newline  (\n).  Since  the  writeln()  method
               automatically creates a newline, the output will display two newlines: the default value
               and the \n in the string.
          5.   This string contains a backslash sequence that will be translated into Unicode. The Unicode
               hexidecimal character 233a is preceded by a \u.
          The process of joining strings together is called concatenation. The string concatenation operator
          is a plus sign (+). Its operands are two strings. If one string is a number and the other is a string,
          JavaScript will still concatenate them as strings.

               !

             Caution  If both operands are numbers, the + will be the addition operator.
          The following examples output “popcorn” and “Route 66”, respectively.
          document.write(“pop”  +  “corn”);
          document.write(“Route  “  +  66);
          The expression 5 + 100 results in 105, whereas “5” + 100 results in “5100”.

          Boolean Literals

          Boolean literals are logical values that have only one of two values,  true or false. You can think
          of the values as yes or no, on or off, or 1 or 0. They are used to test whether a condition is true or
          false.



             Did u know?  When using  numeric  comparison and  equality operators, the value  true
             evaluates to 1 and false evaluates to 0.

          answer1 = true;
           or
          if (answer2 == false) { do something; }

          6.6.2 Composite Data Types

          We mentioned that there are two types of data: primitive and composite. The primitive types:
          numbers, strings, and Booleans—each storing a single value. Composite data types, also called
          complex types, consist of more than one component.




                                           LOVELY PROFESSIONAL UNIVERSITY                                   71
   73   74   75   76   77   78   79   80   81   82   83