Get ready for CBSE Sample Paper 2025 with these 50 important questions and answers from Class 12 Web Application Chapter – JavaScript (Part 2). Based strictly on the latest syllabus, this guide helps you score high in your board exams.
Chapter 2: JavaScript (Part 2) – 50 Important Questions and Answers
Table of Contents
1 Mark Questions (Very Short Answer)
- What is JavaScript?
Answer: JavaScript is a lightweight scripting language used to make web pages interactive. - How is JavaScript different from Java?
Answer: JavaScript is for client-side scripting; Java is a general-purpose programming language. - What is a variable in JavaScript?
Answer: A variable stores data values. Example: var x = 10; - Name three JavaScript data types.
Answer: Number, String, Boolean. - What is the output of typeof(42)?
Answer: ‘number’ - What is the use of the return statement?
Answer: It returns a value from a function. - What are arrays in JavaScript?
Answer: Arrays store multiple values in one variable. Example: var arr = [1, 2, 3]; - What is the use of loops in JavaScript?
Answer: To repeat a block of code multiple times. - What symbol is used for comments in JavaScript?
Answer: // for single-line, /* */ for multi-line. - How do you terminate a statement in JavaScript?
Answer: With a semicolon ;.
CBSE Sample Paper 2025: 2 Mark Questions
- Write a program to add two numbers.
Answer: var a = 5, b = 3;
var sum = a + b;
console.log(sum);
- Define function with syntax.
Answer: A function performs a task.
function name() {
/* code */
}
- What are global and local variables?
Answer: Global: accessible everywhere. Local: only within a function. - Name types of loops in JavaScript.
Answer: for, while, and do-while. - Write syntax of a for loop.
Answer: for(initial; condition; increment) { /* code */ }
- How to access second element of array arr?
Answer: arr[1] - How do you find length of a string?
Answer: “Hello”.length returns 5. - What is the difference between == and ===?
Answer: == compares values, === compares value and type. - What is typeof operator used for?
Answer: To get the type of a variable. - Name any two arithmetic operators.
Answer: + (Addition), – (Subtraction)
CBSE Sample Paper 2025: 3 Mark Questions
- Write a function to calculate square of a number.
Answer: function square(n) {
return n * n;
}
- Write a program to print all elements of an array.
Answer: var arr = [1, 2, 3];
for(var i = 0; i < arr.length; i++) {
console.log(arr[i]);
}
- Difference between while and do-while loop.
- while: checks condition before executing
- do-while: checks after first execution
- Write a program using while loop to print numbers 1 to 3.
Answer: var i = 1;
while(i <= 3) {
console.log(i);
i++;
}
- Write syntax of do-while loop.
Answer: do {
// code
} while (condition);
- What is an object in JavaScript?
Answer: A collection of key-value pairs.
Example: { name: “John”, age: 20 } - Write code to create a student object.
Answer: var student = { name: “Aman”, age: 17 };
- How to access object property name?
Answer: student.name or student[“name”] - Write a function to reverse a string.
Answer: function reverse(str) {
return str.split(”).reverse().join(”);
}
- Write a function to convert Celsius to Fahrenheit.
Answer: function convert(c) {
return (c * 9/5) + 32;
}
CBSE Sample Paper 2025: 5 Mark Questions
- Write a function to find factorial of a number.
Answer: function factorial(n) {
let f = 1;
for(let i = 1; i <= n; i++) {
f *= i;
}
return f;
}
- Write a function to check if a number is even or odd.
Answer: function check(num) {
if(num % 2 == 0)
return “Even”;
else
return “Odd”;
}
- Write a function to find max of three numbers.
Answer: function max(a, b, c) {
return Math.max(a, b, c);
}
- Write a function to count vowels in a string.
Answer: function countVowels(str) {
return str.match(/[aeiou]/gi).length;
}
- Write a program to print numbers from 1 to 10 using for loop.
Answer: for(let i = 1; i <= 10; i++) {
console.log(i);
}
- Write a function to sum elements of an array.
Answer: function sumArray(arr) {
let sum = 0;
for(let i of arr) {
sum += i;
}
return sum;
}
- Write a function to check if a number is prime.
Answer: function isPrime(n) {
if(n < 2) return false;
for(let i = 2; i < n; i++) {
if(n % i == 0) return false;
}
return true;
}
- Difference between var, let, and const.
- var: function scoped
- let: block scoped
- const: block scoped, cannot be reassigned
- What is hoisting in JavaScript?
Answer: Variable and function declarations are moved to the top of their scope before execution. - Write a program using break to exit a loop.
Answer: for(let i = 1; i <= 10; i++) {
if(i === 5) break;
console.log(i);
}
- What is null and undefined?
- null: intentional absence of value
- undefined: variable declared but not assigned
- What is DOM?
Answer: DOM (Document Object Model) allows JavaScript to interact with HTML. - Write syntax to write a comment in JavaScript.
Answer: // This is a comment
/* Multi-line comment */ - What is the difference between parseInt() and parseFloat()?
Answer: parseInt() returns integer part, parseFloat() returns floating point. - How to convert string “123” to a number?
Answer: Using Number(“123”) or parseInt(“123”). - What is scope?
Answer: The context where variables are accessible — local or global. - How to write an arrow function in JavaScript?
Answer: const add = (a, b) => a + b;
- What are control statements?
Answer: Statements that control the flow of execution — like if, switch, loops. - Explain continue statement with example.
Answer: Skips the current iteration.
for(let i=1; i<=5; i++) {
if(i == 3) continue;
console.log(i);
}
- Write a JavaScript program to print a multiplication table of 5.
Answer:
for(let i = 1; i <= 10; i++) {
console.log(“5 x ” + i + ” = ” + (5 * i));
}
Also Read: CBSE Web Application class 12 sample paper: Emerging Trends