Page 131 - CITS - Computer Software Application -TT
P. 131

COMPUTER SOFTWARE APPLICATION - CITS




                                   <=                           less than or equal to
                                   ?                            ternary operator
           Note
           Comparison operators are fully described in the JS Comparisons chapter.

           JavaScript String Comparison
           All the comparison operators above can also be used on strings:
           Example
           let text1 = “A”;

           let text2 = “B”;
           let result = text1 < text2;
           Note that strings are compared alphabetically:
           Example
           let text1 = “20”;

           let text2 = “5”;
           let result = text1 < text2;
           JavaScript String Addition
           The + can also be used to add (concatenate) strings:
           Example

           let text1 = “John”;
           let text2 = “Doe”;
           let text3 = text1 + “ “ + text2;
           The += assignment operator can also be used to add (concatenate) strings:
           Example

           let text1 = “What a very “;
           text1 += “nice day”;
           The result of text1 will be:
           What a very nice day

           Note
           When used on strings, the + operator is called the concatenation operator.
           Adding Strings and Numbers
           Adding two numbers, will return the sum, but adding a number and a string will return a string:
           Example
           let x = 5 + 5;

           let y = “5” + 5;
           let z = “Hello” + 5;
           The result of x, y, and z will be:
           10

           55
           Hello5



                                                           118

                             CITS : IT&ITES - Computer  Software Application - Lesson 37 - 46
   126   127   128   129   130   131   132   133   134   135   136