Anjeev Singh Academy

# Class 12 Web Application 803 CBSE Previous Year Question Answer 2022 Java Script

Previous Year CBSE Board Question Paper 2022-2017

CLASS XII WEB APPLICATION (SUBJECT CODE -803)

CHAPTER 3- WEB SCRIPTING – JAVASCRIPT

Answer Key of Previous Year Questions | 2022 Main Examination

1 – Mark Questions

1. Write the output of the following code: NaN + 5

Answer: NaN

2. Write a statement in JavaScript to declare a variable Sum and initialize it with 10.

Answer: var Sum = 10 ;

3. How many times will the following loop run?

for(var i = 0; i <= 5; i++)

{

..

..

}

Answer:  Six times

4. Write the examples of any two logical operators you know.

Answer: Logical Operators are

• && – Logical AND,
• ||  – Logical OR), and
• !  –  Logical NOT

2 – Marks Questions

5. Write any two ways to convert a string to number in JavaScript.

Answer: In JavaScript a number can be converted to String by using following ways:

• Unary + operator (Concatenation)
• toString( )

Example:

var num = 25;

x = “”+ num;

y = num.toString();

document.write(typeof(x) + “<br>”);

document.write(typeof(y)  + “<br>”);

Output:

string
string

6. Write a command to declare an array ‘AR’. Explain any one property of an array.

Answer: var AR = [10, 20, 30];

Or

var AR = new Array();

AR[0] = 10;

AR[1] = 20;

AR[2] = 30

Properties of Array:

length: length is the magical property of array, which returns the length or size of the array. The length value is always one more than the highest index in the array.

Example:

document.write(“The length of array AR is “ + AR.length);

Output:

The length of array AR is 3

7. What do you understand by properties and methods of an object?

Answer: Every object has its own properties and methods.

• Properties define the characteristics of an object. Examples are color, length, name,

height, width etc.

• Methods are the actions that the object can perform or that can be performed on the object. Examples are alert, confirm, write, open, close etc.

3 – Marks Questions

8. Write a function in JavaScript that accepts two integer variables and return their sum.

Answer:

<script type=”text/javascript”>

function SumTwoNumber(n1, n2)

{

var sum = n1+n2;

return sum;

}

var x = parseInt(prompt(“Number 1 “));

var y = parseInt(prompt(“Number 2 “));

var total = SumTwoNumber(x, y);

document.write(“Number 1 : ” + x + “<br>”);

document.write(“Number 2 : ” + y + “<br>”);

document.write(“Sum :” + sum + “<br>”);

</script>

Output:

Number 1 : 10
Number 2 : 20
Sum :30

9. Explain the term inner function in JavaScript with an example.

Answer: Inner Function: In JavaScript, function declared inside the another function, is called Inner Function.

An important feature of nested functions in JavaScript is that they can access variables in their parent function’s scope.

Example:

function betterExampleNeeded()

{

var a = 1;

function oneMoreThanA()

{

return a + 1;

}

return oneMoreThanA();

}

10. Explain the uses of reverse method of JavaScript. Write a function ‘Revrs’ in JavaScript to explain reverse the order of elements in a given array.

Answer: reverse() : Reverses the order of an element in an array.

<script>

var alphabet=[“z”,”k”,”j”,”h”,”e”];

function Revrs()

{

alphabet.reverse();

return alphabet;

}

document.write(Revrs());

</script>

Output:

e,h,j,k,z

4 – Marks Questions

11. Write a program in Java Script that accepts three number from the user and displays the average value.

Answer:

<html>

<head>

<title>Average of Three Numbers</title>

</head>

<body>

<script type=”text/javascript”>

x = parseInt(prompt(“Number 1 “));

y = parseInt(prompt(“Number 2 “));

z = parseInt(prompt(“Number 3 “));

average = (x  + y + z)/3;

document.write(“Number 1 : ” + x + “<br>”);

document.write(“Number 2 : ” + y + “<br>”);

document.write(“Number 3 : ” + z + “<br>”);

document.write(“Average Value is : ” + average + “<br>”);

</script>

</body>

</html>

Output:

Number 1 : 10
Number 2 : 20
Number 3 : 30
Average Value is : 20

12. Predict the output of the following:

<html>

<body>

<script>

var str=”Honesty is the best policy”;

document.write(str.match(“policy”)+”<br>”);

document.write(str.match(“Police”)+”<br>”);

document.write(str.match(“pollicy”)+”<br>”);

document.write(str.match(“policy”)+”<br>”);

</script>

</body>

</html>

Answer: match() : search for a text in a string and return the text if found using match().

Output:

policy
null
null
policy

Sorry! You cannot copy content of this page. Please contact, in case you want this content.

Scroll to Top