Page 272 - Web_Application_v2.0_C12_Fb
P. 272

ii.   concat() joins two or more strings.
                      var result = "Harry".concat("Potter");
                      document.write(result);
                       Output:
                       HarryPotter
                     iii. charAt()
                        Returns the character at a specified index.
                       var str = "JavaScript";

                      var result = str.charAt(4);
                      document.write(result);
                       Output:
                       S
                     iv.  trim()

                      Removes whitespace from both ends of a string.
                      var str = " Hello World ";
                      var result = str.trim();
                      document.write(result);
                       Output:
                        Hello World
                  2.  Differentiate between Property and Method through an example.

               Ans.
                                            Property                                         Method
                     Property can be value or function.                    Method is a function

                     Property  defines  the  characteristics  of  an  object  like  size,  Methods performs an action on objects.
                     colour etc.
                     Example:                                              Example:
                     var student = {                                       var teacher = {
                     name: "Rahul",              //Property                greeting: function() {
                     age : 45                    //Property                //Method
                      };                                                   document.write ("Welcome");
                                                                           }};
                  3.  What are objects in JavaScript? Explain with an example.
               Ans.  In JavaScript, an object is a collection of key-value pairs where keys are strings (or Symbols) and values can be any
                    data type, including numbers, strings, functions, or even other objects. Objects allow you to store and organize
                    related data efficiently.
                     You can create an object using object literals {} or using the new Object() constructor.
                     For example:

                    const person = {
                    name: "John",
                    age: 30,
                    city: "New York"
                    };
                    console.log(person.name); // Output: John
                    console.log(person.age);  // Output: 30

                270   Touchpad Web Applications (Ver. 2.0)-XII
   267   268   269   270   271   272   273   274   275   276   277