
Q1
Q1 What is the purpose of JavaScript in web development?
To structure web pages
To style web pages
To add interactivity and dynamic content to web pages
To store data on the server
Q2
Q2 Which keyword is used for declaring a variable in JavaScript that can be reassigned?
const
var
let
static
Q3
Q3 In JavaScript, which of the following is a valid variable name?
2names
$name
-name
name2
Q4
Q4 Which data type in JavaScript is used to represent logical values?
String
Boolean
Number
Undefined
Q5
Q5 What does the undefined value in JavaScript represent?
An unassigned variable
A null value
A logical false
An error condition
Q6
Q6 What will be the output of the following code?
console.log(typeof null);
'object'
'null'
'undefined'
'number'
Q7
Q7 What is the output of the following code snippet?
var a = 10;
console.log(a);
10
'10'
undefined
null
Q8
Q8 Which statement is used to execute a block of code multiple times in JavaScript?
for
if
return
break
Q9
Q9 What does the if statement in JavaScript do?
Declares a variable
Executes a block of code based on a condition
Prints a message to the console
Loops through a block of code
Q10
Q10 Which of the following is not a loop structure in JavaScript?
while
for
if
do-while
Q11
Q11 In a switch statement, what keyword is used to terminate a case in JavaScript?
end
break
stop
exit
Q12
Q12 What will be the output of the following code?
let a = 2;
if(a > 3) {
console.log('Yes');
} else {
console.log('No');
}
Yes
No
Undefined
Error
Q13
Q13 In a for loop, what are the three optional expressions, separated by semicolons?
Initializer, Condition, Incrementer
Condition, Incrementer, Initializer
Incrementer, Initializer, Condition
Condition, Initializer, Incrementer
Q14
Q14 Identify the problem in this code:
let i = 0;
while (i < 3) {
console.log(i);
}
Infinite loop
Syntax error
Logical error
No output
Q15
Q15 What is the result of trying to extend the length of an array using a function in JavaScript?
function extendArray(arr) {
arr.push(5);
}
let myArr = [1, 2, 3];
extendArray(myArr);
console.log(myArr.length);
3
4
5
Error
Q16
Q16 What does the following function return?
function checkEven(number) {
return number % 2 === 0;
}
console.log(checkEven(3));
true
false
3
Error
Q17
Q17 In JavaScript, how can you check if a variable is an array?
typeof variable
variable.isArray()
Array.isArray(variable)
variable instanceof Array
Q18
Q18 What is the output of the following code?
let fruits = ['apple', 'banana', 'mango'];
console.log(fruits[1]);
apple
banana
mango
undefined
Q19
Q19 Consider the following code:
let arr = [1, 2, 3];
arr[5] = 5;
console.log(arr.filter(x => x === undefined).length);
What is the output?
0
2
3
5
Q20
Q20 Spot the mistake in this code snippet:
let data = [1, 2, 3];
delete data[1];
console.log(data[1]);
undefined is logged instead of 2
2 is not deleted
Syntax error
No error
Q21
Q21 What will be the output of console.log(typeof {})?
'object'
'array'
'null'
'undefined'
Q22
Q22 In JavaScript, what is a method?
A predefined function
A loop inside an object
A function stored as an object property
An external library function
Q23
Q23 How do you create a new object in JavaScript?
Object.create()
new Object()
Both A and B
Neither A nor B
Q24
Q24 What is the purpose of the this keyword in JavaScript objects?
Refer to the global object
Refer to the current object
Create a new object
Duplicate an object
Q25
Q25 What is the result of accessing a property that doesn’t exist on an object?
null
undefined
0
Error
Q26
Q26 What is the output of the following code snippet?
let obj = { a: 1, b: 2 };
console.log(obj.a);
1
2
undefined
Error
Q27
Q27 Consider the code:
let person = { name: 'Alice', age: 25 };
delete person.age; console.log(person.age);
What is the output?
'Alice'
25
undefined
Error
Q28
Q28 Given the following code, what is printed to the console?
let obj1 = { a: 1 };
let obj2 = { a: 1 };
console.log(obj1 === obj2);
true
false
null
Error
Q29
Q29 What does DOM stand for in web development?
Document Object Model
Data Object Management
Direct Object Manipulation
Display Object Model
Q30
Q30 How can you change the text content of an HTML element in the DOM using JavaScript?
element.textContent = 'new text'
element.innerHTML = 'new text'
Both A and B
Neither A nor B

