Web Scripting JavaScript Class 12 QA

Teachers and Examiners collaborated to create the Web Scripting JavaScript Class 12. All the important Questions and Answers and taken from the NCERT Textbook Web Application ( 803 ).

Web Scripting JavaScript Class 12

JavaScript Introduction

1. What is JavaScript?

Answer – JavaScript is a text-based programming language for creating dynamic web pages. It may be used both on the client-side and server-side. Whereas HTML and CSS provide structure and design to web pages, JavaScript adds interactive components that keep users engaged.

2. How is JavaScript different from Java?

Answer – Brendan Eich of Netscape created JavaScript, whereas Sun Microsystems created Java. Despite the fact that the two languages overlap certain syntax, they were created independently and for different audiences.

3. What is the relationship between JavaScript and ECMAScript?

Answer – ECMAScript is yet another name for JavaScript (other names include LiveScript). The current JavaScript that you see supported in browsers is ECMAScript

4. What are the advantages of JavaScript?

Answer – The advantages of JavaScript are –
a. Developing Multimedia Application – Users can add multimedia elements like animation, audio files, video files etc.
b. Create pages dynamically – Based on the data user can make modifications in the data dynamically.
c. Interact with the user – JavaScript can validate user response when the user submit the form.

5. What are the features of JavaScript?

Answer – The features of JavaScript are –

a. Browser Support – All the browsers support the JavaScript program without using any plugins.
b. Client Side and Server Side – JavaScript programs can be written in Client Side and Server Side in both conditions.
c. Functional Programming Language – In JavaScript support function program, function just like a data type. Function can accept parameters and can also return the value.
d. Support for Objects – JavaScript handles the objects easily like Array, String and Math. It also supports Inheritance concepts just like C++ and Java programs.

6. What are the various data types in JavaScript?

Answer –
a. Number – JavaScript uses a double-precision 64-bit representation for numbers. Addition, subtraction, multiplication, division, modulus etc.
b. String – Strings are character sequences in JavaScript. They’re actually sequences of Unicode characters, each of which is represented by a 16-bit number.
c. Boolean – The boolean type in JavaScript has two potential values: true and false.
d. Null – You can give a variable the value null to indicate that it does not have a value right now but will later. A null value denotes the absence of a value.
e. Undefined – When no value is assigned to a variable or object before it is used, it has an undefined value.

7. Can you explain what isNaN function does?

Answer – If the argument does not appear to be a number, the isNaN function will return TRUE (1).

8. What is the difference between undefined value and null value?

Answer – The term “undefined” refers to a variable that has been declared but not yet given a value. Null, on the other hand, is a value assigned to a variable. It can be assigned to a variable as a no-value representation.

9. Define the characteristics of JavaScript?

Answer – JavaScript is a client-side and server-side technology mostly used for client-side validation, but it also contains a lot of other features that are listed below:
– JavaScript is a scripting language that is built on objects.
– JavaScript allows users to have more control over their browser.
– It recognizes the browser and operating system used by the user.
— It’s a scripting language, not a programming language like Java.
– JavaScript is an interpreter based scripting language.
– JavaScript is a case sensitive language.
– In JavaScript, every statement must be followed by a semicolon (;).

10. Is JavaScript case-sensitive?

Answer – Yes, JavaScript is a case-sensitive language. This means that language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters.

11. What is a Document Object Model?

Answer – The Document Object Model (DOM) is an HTML and XML programming interface. It specifies the logical structure of documents as well as how they are accessed and modified.

12. What is Client-side & Server-side JavaScript?

Answer –
a. Client – side – Client-side scripting is carried out by web browsers. When all of the code is present in the browser, it is used. The source code is used to transport data from a web server to a user’s machine via the internet and run it directly in browsers. It’s also utilised for validations and user event functions.

b. Server – side – Server-side scripting is carried out by web servers. Basically, they’re used to make dynamic pages. It also has access to the web server’s file system. A webserver is a server-side environment that runs on a server side.

13. Explain the following functions with respect to JavaScript:
a) Substring
b) Concat()
c) Shift()

Answer –
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

14. What is the difference between entry control loop & exit control loop?

Answer – Loops are a technique for repeatedly repeating a group of statements until a condition is met. There are three types of loops in the JavaScript programming language: 1) while loop, 2) do while loop, and 3) for loop.
As a result, loops can be managed in two ways: at the entry level or at the exit level.

1. Entry Controlled Loop

2. Exit Controlled Loop

Entry Controlled Loop
Loop, where the test condition is checked before entering the loop body, known as Entry Controlled Loop.
Example: while loop, for loop

Exit Controlled Loop
Loop, where the test condition is checked after executing the loop body, known as Exit Controlled Loop.
Example: do-while loop

15. What is an event in JavaScript?

Answer – The interaction between JavaScript and HTML is handled via events that occur when the user or the browser manipulates a page. Event Handling refers to the process of reacting to situations. When the page loads, the mouse moves on the page, the user clicks on the button these all are examples of events.
Different types of event in JavaScript
a. onLoad – occurs when a page loads in a browser
b. onUnload – occurs just before the user exits a page
c. onMouseOver – occurs when you point to an object
d. onMouseOut – occurs when you point away from an object
e. onSubmit – occurs when you submit a form
f. onClick – occurs when an object is clicked

Web Scripting JavaScript Class 12

Control Statements 

If, else, else if, and switch-case statements are all conditional statements in JavaScript. They’re used to check for a specific condition and then run the code based on the result.

// Write a program to accept two numbers from the user and find the greatest numbers

<html>
<body>
<script type="text/javascript">
	var num1, num2;
	num1=parseInt(prompt("Enter 1st Number"));
	num2=parseInt(prompt("Enter 2nd Number"));
	if(num1 > num2)
	{
		document.write("1st Number is greatest");
	}
	else
	{
		document.write("2nd Number is greatest")
	}
</script>
</body>
</html>

// Write a program to accept numbers from the user and check the number is even or odd

<html>
<body>
<script type="text/javascript">
	var num1;
	num1=parseInt(prompt("Enter Number"));
	
	if(num1%2==0)
	{
		document.write("Number is even");
	}
	else
	{
		document.write("Number is Odd")
	}
</script>
</body>
</html>

// Write a program to accept three numbers from the user and find the greatest numbers

<html>
<body>
<script type="text/javascript">
	var num1, num2, num3;
	num1=parseInt(prompt("Enter 1st Number"));
	num2=parseInt(prompt("Enter 2nd Number"));
	num3=parseInt(prompt("Enter 3rd Number"));
	if(num1 > num2 && num1 > num3)
	{
		document.write("1st Number is greatest");
	}
	else if(num2 > num3)
	{
		document.write("2nd Number is greatest");
	}
	else
	{
		document.write("3rd Number is greatest")
	}
	
</script>
</body>
</html>

// Write a JavaScript program to check vowels or consonants using switch cases.

<html>
<body>
<script type="text/javascript">
	var ch;
	ch=prompt("Enter any small character");
	switch(ch)
	{
		case 'a':
		document.write("Vowel");
		break;

		case 'e':
		document.write("Vowel");
		break;

		case 'i':
		document.write("Vowel");
		break;

		case 'o':
		document.write("Vowel");
		break;

		case 'u':
		document.write("Vowel");
		break;

		default:
		document.write("Consonant");
	}
</script>
</body>
</html>

Web Scripting JavaScript Class 12

Looping Statements

Using a loop you can execute the statement multiple times.

There are three types of loop.

  1. For loop
  2. While loop
  3. Do-While loop

For Loop

// Write a program to print the number from 1 to 10 using for loop

<html>
<body>
<script type="text/javascript">
	var i;
	for(i=1;i<=10;i++)
	{
		document.write(i);
	}
	
</script>
</body>
</html>

// Write a program to print the number from 10 to 1 using for loop

<html>
<body>
<script type="text/javascript">
	var i;
	for(i=10;i>=1;i--)
	{
		document.write(i);
	}
	
</script>
</body>
</html>

// Write a program to print the even numbers from 1 to 100 using for loop

<html>
<body>
<script type="text/javascript">
	var i;
	for(i=1;i<=100;i++)
	{
		if(i%2==0)
		{
		document.write(i);
		}
	}
	
</script>
</body>
</html>

// Write a program to accept 10 numbers from the user and find the greatest number using a for loop.

<html>
<body>
<script type="text/javascript">
	var i, num, max;
	max=parseInt(prompt("Enter Number"));
	for(i=1;i<=10;i++)
	{
		num=parseInt(prompt("Enter Number"));
		if(num > max)
		{
		max = num;
		}
	}
	document.write("Greatest Number is " + max);
</script>
</body>
</html>

// Write a program to accept 10 numbers from the user and sum of numbers using a for loop.

<html>
<body>
<script type="text/javascript">
	var i, num, sum=0;
	for(i=1;i<=10;i++)
	{
		num=parseInt(prompt("Enter Number"));
		sum=sum+num;
	}
	document.write("Sum is " + sum);
</script>
</body>
</html>

While Loop

// Write a program to print the number from 1 to 10 using a while loop.

<html>
<body>
<script type="text/javascript">
	var i;
	i=1;
	while(i<=10)
	{
		document.write(i);
		i++;
	}
</script>
</body>
</html>

Do-While Loop

// Write a program to print the number from 1 to 10 using a do-while loop.

<html>
<body>
<script type="text/javascript">
	var i;
	i=1;
	do
	{
		document.write(i);
		i++;
	}while(i<=10);
</script>
</body>
</html>

Web Scripting JavaScript Class 12

Array in JavaScript

Array is a group of variables which have the same name.
There are three different ways to declare array variables.
a. var a = new Array();
b. var a = [10];
c. var a =[“Apple”, “Mangoes”, “Orange”, “Banana”];

Note – Array variable always start from 0

First Method

// Write a JavaScript program to accept 10 numbers from the user and print the numbers using an array.

<html>
<body>
<script type="text/javascript">
	var a = new Array();
 	var i;
 	for(i=0;i<=9;i++)
 	{
 		a[i]=parseInt(prompt("Enter Number"));
 	}
 	for(i=0;i<=9;i++)
 	{
 		document.write(a[i]);
 	}
</script>
</body>
</html>

Second Method

// Write a JavaScript program to accept 10 numbers from the user and print the numbers using an array.

<html>
<body>
<script type="text/javascript">
	var a = [10];
 	var i;
 	for(i=0;i<=9;i++)
 	{
 		a[i]=parseInt(prompt("Enter Number"));
 	}
 	for(i=0;i<=9;i++)
 	{
 		document.write(a[i]);
 	}
</script>
</body>
</html>

Third Method

// Write a JavaScript program to print the number from 1 to 5.

<html>
<body>
<script type="text/javascript">
	var a = ["1", "2", "3", "4", "5"];
 	var i;
 	for(i=0;i<=4;i++)
 	{
 		document.write(a[i]);
 	}
</script>
</body>
</html>

Web Scripting JavaScript Class 12

String in JavaScript

Combination of characters is know as string.

// Write a program to display the middle value from the string using substring.

<html> 
<body> 
<script> 
var str, result;
str=prompt("Enter String");
result=str.substring(1, 4);
document.write(result);
</script> 
</body> 
</html>

Answer - 
Input - INTERNATIONAL
Output - NTE

// Write a program to concatenate the two given strings.

<html> 
<body> 
<script> 
var str1, str2, result;
str1=prompt("Enter String");
str2=prompt("Enter String");
result=str1.concat(str2);
document.write(result);
</script> 
</body> 
</html>

Answer - 
Input - Str1 = Hello, Str2 = World
Output - HelloWorld

// Write a program to join the array string using join.

<html> 
<body> 
<script> 
var str=["Hello", "World"];
var result;
result=str.join();
document.write(result);
</script> 
</body> 
</html>

Answer - 
Input - str=[“Hello”,”World”];
Output - Hello, World

Note - Join function is used to convert array string to normal string.

// Write a program to remove the last element from the string.

<html> 
<body> 
<script> 
var str=["Welcome", "to", "New", "World"];
str.pop()
document.write(str);
</script> 
</body> 
</html>

Answer - 
Input - str=["Welcome", "to", "New", "World"];
Output - Welcome,to,New

Note - Pop is used to remove the last element from the array.

// Write a program to add the last element in the array string.

<html> 
<body> 
<script> 
var str=["Welcome", "to", "New"];
str.push("World");
document.write(str);
</script> 
</body> 
</html>

Answer - 
Input - str=["Welcome", "to", "New"]; str.push("World");
Output - Welcome,to,New,World

Note - In the array you can add new element in the last 

 // Write a program to display the array elements in reverse order.

<html> 
<body> 
<script> 
var str=["Welcome", "to", "New", "World"];
str.reverse();
document.write(str);
</script> 
</body> 
</html>

Answer - 
Input - str=["Welcome", "to", "New", "World"];
Output - World,New,to,Welcome

// Write a program to remove the first element from the array.

<html> 
<body> 
<script> 
var str=["Welcome", "to", "New", "World"];
str.shift();
document.write(str);
</script> 
</body> 
</html>

Answer - 
Input - str=["Welcome", "to", "New", "World"];
Output - to,New,World

// Write a program to remove the first element from the array.

<html> 
<body> 
<script> 
var str=["Banana", "Orange", "Lemon", "Apple", "Mango"];
var result;
result = str.slice(1, 4);
document.write(result);
</script> 
</body> 
</html>

Answer - 
Input - str=["Banana", "Orange", "Lemon", "Apple", "Mango"];
Output - Orange,Lemon,Apple
 

// Write a program to sort the array elements.

<html> 
<body> 
<script> 
var str=["Banana", "Orange", "Lemon", "Apple", "Mango"];
var result;
result = str.sort();
document.write(result);
</script> 
</body> 
</html>

Answer - 
Input - str=["Banana", "Orange", "Lemon", "Apple", "Mango"];
Output - Apple,Banana,Lemon,Mango,Orange

// Write a program to add the new element in the array.

<html> 
<body> 
<script> 
var str=["Banana", "Orange", "Lemon", "Apple", "Mango"];
var result;
str.splice(2, 0, "Lichi", "Kiwi");
document.write(str);
</script> 
</body> 
</html>

Answer - 
Output - Banana,Orange,Lichi,Kiwi,Lemon,Apple,Mango  
Note - Splice will add the new element after two element 

// Write a program to add the new element in the beginning of the array.

<html> 
<body> 
<script> 
var str=["Banana", "Orange", "Lemon", "Apple", "Mango"];
var result;
str.unshift("Lemon", "Kiwi");
document.write(str);
</script> 
</body> 
</html>

Answer - 
Output  -   Lemon,Kiwi,Banana,Orange,Lemon,Apple,Mango  
  
Note - unshift allows you to add a new element before the first array element.   

Web Scripting JavaScript Class 12

Function in JavaScript

In JavaScript, functions can be declared using the function keyword, followed by the function name, and, in parentheses, the list of parameters (without a var declaration). The actual function definition is enclosed in curly brackets. The return keyword is used to return a value or just terminate the function. 

Syntax – 

function function-name(parameter-list)

declarations and statements 

// Write a program to accept two numbers from the user and find the sum of two numbers using function;

<html> 
<body> 
<script> 
function sum(x, y)
{
  var sum;
  sum=x+y;
  return sum;
}
var num1, num2, result;
num1=parseInt(prompt("Enter Number"));
num2=parseInt(prompt("Enter Number"));
result = sum(num1, num2);
document.write("Sum is " + result);
</script> 
</body> 
</html>

Web Scripting JavaScript Class 12

Math in JavaScript

// Write a program to accept decimal values from the user and roundup the value.

<html> 
<body> 
<script> 
var num, result;
num=parseFloat(prompt("Enter Number"));
result = Math.round(num)
document.write(result);
</script> 
</body> 
</html>

// Write a program to display any random value from 0 to 1.

<html> 
<body> 
<script> 
var result;
result = Math.random();
document.write(result);
</script> 
</body> 
</html>

// Write a program to find the maximum value from 5 numbers.

 54, 38, 71, 44, 92

<html> 
<body> 
<script> 
var result;
result = Math.max(54, 38, 71, 44, 92);
document.write(result);
</script> 
</body> 
</html>

// Write a program to find the minimum value from 5 numbers.

 54, 38, 71, 44, 92

<html> 
<body> 
<script> 
var result;
result = Math.min(54, 38, 71, 44, 92);
document.write(result);
</script> 
</body> 
</html>

Events in JavaScript

// Onload event

<html> 
<script> 
function myFunction()
{
  confirm("Welcome to the browser");
}
</script>
<body onload="myFunction()"> 
</body> 
</html>

// OnClick event

<html> 
<script> 
function myFunction()
{
  confirm("You have clicked on the button");
}
</script>
<body> 
<button onclick="myFunction()">Click me</button>
</body> 
</html>

Employability Skills Class 12 Notes

Employability Skills Class 12 MCQ

Employability Skills Class 12 Questions and Answers

Web Application Class 12

Reference Textbook

The above Web Scripting JavaScript Class 12 was created using the NCERT Book and Study Material accessible on the CBSE ACADEMIC as a reference.

Your valuable Feedback

Hi Students, Thank you for taking the time to reading Web Scripting JavaScript Class 12. Please take a few moments and leave your thoughts in the comment box below.

Disclaimer – 100% of the questions are taken from the CBSE textbook Web Scripting JavaScript Class 12, and our team has tried to collect all the correct Question and Answer from the textbook . If you found any suggestion or any error please contact us anuraganand2017@gmail.com.

Leave a Comment

error: Content is protected !!