[Go to site: main page, start]

0% found this document useful (0 votes)
9 views12 pages

JavaScript Web Scripting Questions and Answers

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views12 pages

JavaScript Web Scripting Questions and Answers

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Web Applications

Class- XII

Chapter-3

Web Scripting- Java Script

1 mark Questions
Q1. JavaScript was developed by ________.

Ans. Brendan Eich

Q2. JavaScript was initially named as ________.

Ans. LiveScript

Q3. The ____________ tag is the web standard for embedding content on to a web page

a) <p>

b) <object>

c) <html>

d) <content>

Ans. <object>

Q4. Identify the statement that is false with respect to JavaScript:

a) JavaScript is Object Oriented programming language.

b) JavaScript function can accept another function as a parameter

c) It is possible to instantiate the defined object types to create object instances in

JavaScript

d) The users cannot use JavaScript to add multimedia elements.

Ans d) The users can use JavaScript to add multimedia elements.

Q5. In JavaScript, objects are just collections of _________ pairs.

a) Variable name
b) Name-value
c) Integer-string
d) Value value
Ans b) Name – value

Q6. ________ tag alerts browser about the scripting language JavaScript

a) <Head>
b) <Body>
c) <Script>
d) <language>

Ans : c) <Script>

Q7. Extension of JavaScript files is ________

a) .html
b) .js
c) .jsc
d) .java

Ans : B) .js

Q8. ________ is called as Bitwise Shift Right with Zero Operator, the bits shifted in on the left are always
zero.

a) <<
b) <<<
c) >>>
d) >>

Ans : c) >>>

Q9. A ___________ is a classification of the type of data that a variable or object can hold.

a) Datatype
b) Number
c) Variable
d) Object

Ans a) Data Type

Q10. Numbers in JavaScript are double-precision ___________.

a) 16 bit format
b) 32 bit format
c) 8 bit format
d) 64 bit format

Ans : d) 64 bit format

Q11. Built-in object called ________ is used to handle more advanced mathematical functions and
constants.

a) Calculus
b) Maths

c) math

d) Sum

Ans c) math

Q12. _____________ is used to convert string to integer

a) Integer()

b) parsestring()

c) parseInt()

d) Stringtoint()

Ans : c) parseInt()

Q13. A JavaScript function is defined with the____________ keyword.


a) function
b) var
c) If
d) Switch

Ans. A) function

Q14. A ___________ is a memory location where we can store data during the program execution.

a) Datatype
b) Number
c) Variable
d) Object

Ans C) Variable

Q15. ________ is name of the variable.

a) Identifier
b) Datatype
c) Prototype
d) Object

Ans. A) Identifier

Q16. “=” is an ________ operator.

a) Arthmatic Operator
b) Comparison Operator
c) Logical Operator
d) Assignment Operator
Ans. D) Assignment Operator

Q17. Conditional Operators are also known as

a) Ternary Operator
b) Assignment Operator
c) Logical Operator
d) Comparison Operator

Ans. A) Ternary Operator

Q18. Which of the following are not Logical Operators / is a Ternary Operator:

a) &&
b) ||
c) ?:
d) !

Ans. C) ? :

Q20. Predict the output :

var age= 18

(age>20)? “Eligible “ : “Non-Eligible”

Ans. Non-Eligible

Q21. Which of the following is not an looping structure –

a) for loop
b) while loop
c) for-while loop
d) do-while loop

Ans. C) for-which loop

Q22. While is an ________ control loop while do-while is an ________ control loop.

Ans. Entry, Exit

Q23. In JavaScript ________ are used to store multiple values in a single variable.

a) Functions
b) Array
c) Switch
d) Objects

Ans. B. Array

Q24. The length of array is always ________ the highest index.

a) 1 less than
b) 1 more than
c) Equal to
d) 2 less than

Ans. B. 1 more than

Q25. Which of the following removes and returns the last item of an array –

a) Shift()
b) Unshift()
c) Pop()
d) Splice ()

Ans. c) Pop()

Q26. Which of the following add item / add item to the beginning of an array.

a) Shift()
b) Unshift ()
c) Splice()
d) Pop()

Ans. b) Unshift ()

Q27. Write the syntax for embedding a confirm Box and prompt Box.

Ans. Confirm Box- [Link] (“”)

Prompt Box- [Link](“”)

Q28. What is the full form of CSS-

a) Class Style Sheet


b) Class Styling Software
c) Cascading Style Sheet
d) Cascading soft sheet

Ans. c) Cascading Style Sheet

Q29. What is the full form of NaN-

a) Not a Name
b) Not a Number
c) Name a Number
d) Not a natural Number

Ans. b) Not a Number

Q30. Every Object has its own ________ and ________.

a) Properties, data types


b) Variables, methods
c) Variables, data types
d) Properties, methods

Ans. d) properties, methods

Q31. The _______ object provides methods for many mathematical calculations.

a) Math
b) String
c) Array
d) Object

Ans. a) Math

2 marks Questions
Q1. Shyam has written following code to store subjects in an array and display the total number
of subjects in the array. His code is not running properly. Identify and underline the syntax
errors in the following code and write the corrected code:

function countsubs( )
{
Var Subject = [“Eng” , “Math”, “Science” , “Hindi”];
[Link] ([Link])

}
Ans :
function countsubs( )
{
var Subject = [“Eng” , “Math”, “Science” , “Hindi”];
[Link]([Link]);
}
Q2. Explain the term Add-ins and Snippets.
Ans :

Add-ins extends the capability of the main program by adding enhanced custom commands and
specialized features.
Snippets are pieces of programs re-used by most developers. Snippets are useful as you can
keep reusing the code created many times across multiple web pages or web sites saving
enormous amount of time and effort.

Q3. Write Any four applications of JavaScript.


Ans. A) developing multimedia application
B) Create page dynamically
C) interact with the user

D) it is used for in game developing and mobile application


Q4. Write a short note on ‘Functions’.
Ans. Functions are reusable blocks of code that carry out a specific task. To execute the code in
a function we need to call it. A function can be passed through Arguments to Use, and it may
return a value to whatever called it.
Q5. Define the following objects-
1. round() method
2. random()
Ans. 1. The round() method returns a number to the nearest integer.

2. The random() method returns a random number from 0(inclusive) up to but not including
1(exclusive)
Q6. Define the following objects-
1. max()
2. min()
Ans. 1. It returns the number with the highest value.
[Link] returns the number with the lowest value.
3 marks Questions

Q1. Explain the following functions with respect to JavaScript:


a) Substring
b) Concat()
c) Shift()

Ans :
a) Substring : Extracts the characters from a string, between two specified indices
b) Concat() : Joins two or more strings, and returns a copy to the joined strings
c) Shift() : Removes the first element of an array and returns that element

Q2. Write a function in JavaScript which accept three numbers as arguments and
display the greatest number
Ans :
function greatest(n1, n2, n3)

{ if (n1>n2)
If (n1>n3)
alert(“greatest number is : “+ n1);
else

[Link](“greatest number is : “ + n3);


else if ( n2>n3)
[Link](“greatest number is : “ + n2);
else
[Link](“greatest number is : “ + n3);

}
Q3. Differentiate between if-else and switch case. (atleast 3)
Ans.
If-else
1. It works on <, >, >=, <=
2. It works on range.
3. It can take decimal value
Switch

1. It works on equality.
2. It cannot work on range.
3. It can take character and integer value.
Q4. Write a Short note on : (1.5 each)
a) While loop
b) Do-while loop
Ans. A) while loop – It is used in which we do not know that how many times the loop will run.
It is best suitable in a scenario when we do not know that how many times the loop will be
executed. It is known as entry control loop.
B) do-while loop – It is another kind and different from for and while loop. This loop will
execute the statement at least once, even if the condition is false. It is known as exit control
loop.
Q5. Explain the following with respect to Arrays in JavaScript:
a) sort()
b) length
c) push
Ans. A. It is used to arrange the elements of an array in ascending or descending orders.
B. The length Property of an array returns the length of an array that is the number of array
elements.
C. This Method appends a new element to an Existing array every time you execute the
program.
4 marks Questions
Q1. Write a program in JavaScript to
- Accept first name and last name from the user.

- Display number of characters in his first name


- Display current date, his name as initial letter of first name and complete
last name ( hint: it should display K. Kumar for name Krishan Kumar)
Solution :

<html>
<body>
<script >
f=prompt("enter first name ");

l=prompt("enter last name ");


d= new Date ();
[Link](“ today’s date : “, d);
[Link]("length of first name is ", [Link]);
[Link]("\n Your name is ",f[0]+". " +l);

</script>
</body>
</html>
Q2. A) Write a program in JavaScript to display a week day randomly from the array of days of
week given below: (2)
dow=[“Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”,
“Sunday” ]
Ans :

<html><body><script > (2)


n=[Link]([Link]()*7)-1
dow=[“Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”,
“Sunday” ]
[Link]( " Day ", dow[n] );

</script></body></html>
B) Write code in JavaScript to accept a string from the user and display the first
occurrence of word “good” in the entered string. (2)
Ans :
<html>
<body>
<script >
str=prompt(" enter a string : ");

[Link]([Link]("good"));
[Link]("<br>", [Link]("good"));
</script>
</body>
</html>
Q3. A) Predict output of the following : (2)

<html>
<body>
<script >
n =20;

m = n>>2;
x=n<<2;
[Link]("value after right shift is : ", m, );
[Link]("<br> value after left shift is : ", x);

</script></body></html>
Ans :
value after right shift is : 5
value after left shift is : 80
B) Write code snippets in JavaScript to accept height of 5 students in an array

and display the tallest and the smallest height of student.(2)


Ans :
<html>
<body>
<script >
var i = 0;
str=new Array();
while (i<5)

{
str[i]=parseInt(prompt(" enter the height : "));
i++;
}
[Link]();
[Link](“smallest “ , str[0]);

[Link](“Tallest “, str[4]);
</script>
</body>
</html>

Q4. Explain the following-


1. Confirm Box
2. Alert Box
3. Prompt Box
4. Object
Ans. 1. A confirm Box is often used if you want the user to verify or accept something. When a
confirm Box pops up, the user will have to click OK or CANCEL to proceed further.
2. An alert Box is often used if you want to make sure that the information come through to the
user. When an alert box pops up, the user will have to click OK to proceed.

[Link] is often used if you want a user to input a value before entering a page.
4. JavaScript object are simply collection of Name-Value pairs. The ‘name’ part is a JavaScript
string, while the value can be any JavaScript value including more objects.

You might also like