Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

NAME – Bikaraj Singha

SECTION – 1801 ROLL NO - A29


REGISTRATION NO - 11806528
Q1. What are JavaScript objects, what is the two different ways to
create new objects. Discuss it with the help of example.
Ans.
JavaScript objects are entities with their own properties and type, they
can be compared to objects in real life. As in many other programming
languages, for example. A car is an object, with properties. A car has a
color, a design, weight etc. In a same way, JavaScript objects can have
properties which define them.
They are accessed as :–
objectName.propertyName
Ex. myCar.Color
Two different ways to create new objects :–
1. Using NEW keyword
With the help of new keyword an object can be easily created
and it is most common way to create a object in JavaScript.
Ex. Var Car = new object();
2. Using Object literal
By adding a list of key value pairs in curly braces a new
object can be created.
Ex. Var Car = {Weight :”full ton”,
Color :”Blue”,
Cost : “Free”};
Q2. Discuss the role this keyword in JavaScript object and class with
the help of program.
Ans.
Generally, in JavaScript this keyword refers to the object it belongs to.
Program for this in object :
For getting current info of Bikaraj using this keyword
Var A = {
Bikaraj : "Ball",
Bablu :"Sleep",
Emli :"Study",
Info = function funx(){return this.Bikaraj;}
}
A.Info();
>> Ball

Program for this keyword in class :

For initializing key and values in constructor and getting marks

class Bika{
constructor(){
this.height = 171,
this.age = 19
}
}
const a = new Bika();
a.height;
>>171

Q3. How does jQuery events change the behavior of the HTML web
page? Explain it with the help of an example.
Ans.
jQuery events provide a function for a specific event, so the provided
function is executed when a particular event take place. Examples of
events are a mouse click, an HTML form submission, a web page
loading, a keystroke on the keyboard etc. jQuery events helps to specify
a way how a HTML web page reacts to an event.
Example:
To assign a click event to all italic texts on a page:
$(“i”).click ();
The next step is to define what should happen when the event fires. So
we have to pass a function to the event:
$(“i”).click(function(){
//some action goes Here
}
Some other methods are as follows:
$(document).ready() method allow us to execute a function the
document is fully loaded.
click() method attaches an event handler function to an HTML element.
This function is executed when the user clicks on the HTML element.
Mouseenter() method attaches an event handler function to an HTML
element. The function is executed when the mouse pointer enters the
HTMl element
Q4. Write a program in JavaScript to find the number entered by user
is prime or not.
Ans.
<html> <head> <script>
    // Function to check prime number
     function p() {
          var n, i, flag = true;
            n = prompt(“Enter Number”);
            n = parseInt(n);
            for(i = 2; i <= n - 1; i++)
                if (n % i == 0) {
                    flag = false;
                    break;
                }
                // Check and display alert message
            if (flag == true)
                alert(n + " is prime");
            else
                alert(n + " is not prime");
        }
  </script> </head> <body>
        <h1>check number is prime or not</h1>
        <hr>
<form> 
        <input type="button" value="ClickHererToCheck" onClick="p()">
  </form> </body> </html>

You might also like