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

18.  Write a statement in JavaScript to declare a variable ‘Sum’ and initialise it with 10.   [2022 T2]
                Ans.  var Sum = 10;
                19.  How many times will the following loop run?                                              [2022 T2]

                     for (var i = 0; i < = 5; i ++)
                     {
                     ……
                     }
                Ans.  It runs for i values 0, 1, 2, 3, 4, and 5, which is a total of six iterations.
                20.  Write the examples of any two logical operators you know.                                [2022 T2]
                Ans.  i.  AND Operator (&&),  ii.  OR Operator (||)
                21.  Write any two ways to convert a string to a number in JavaScript.                        [2022 T2]
                Ans.  In JavaScript, you can convert a string to a number using the following two common methods:
                     i.     Using parseInt() or parseFloat(): parseInt(string) converts a string to an integer (parseFloat converts to
                        float), parsing it until a non-numeric character is encountered.
                     ii.     Using the Number() constructor:  JavaScript  provides  the  Number()  constructor  that  can  be  used  to
                        explicitly convert a string to a number. It can handle both integers and floating-point numbers.
                22.  Write a command to declare an array ‘AR’. Explain any one property of an array.          [2022 T2]
                Ans.  To declare an array named ‘AR’ in JavaScript, you can use the following command: var AR = [];
                     One important property of an array in JavaScript is its length property. The length property indicates the number
                    of elements in the array.
                     Example:

                    var AR = [10, 20, 30, 40, 50];
                     document.write(AR.length);
                     // Outputs: 5
                23.  What do you understand by the properties and methods of an object?                       [2022 T2]
                Ans.  An object in JavaScript is a collection of properties and methods. Properties are like attributes/characteristics of
                    an object, and methods are like functions that can be performed on an object.
                     Example:

                    const person = {
                       name: "Abhira",
                       age: 22,
                       display() {
                         document.write("Hello " + this.name);
                       }
                     };

                     const P1 = person;
                     P1.display();
                     In this example, the name and age properties are attributes of the person object, and the display() method is a
                    function that can be performed on the person object.









                232   Touchpad Web Applications-XII
   229   230   231   232   233   234   235   236   237   238   239