Font size
WorksheetsJavaScript
Total questions: 70
Worksheet time: 35mins
How do you write "Hello World" in an alert box?
msg("Hello World");
alertBox("Hello World");
alert("Hello World");
alert("Hello World")
JavaScript code can be written directly into an HTML document using the (a) tag.
Which of the following is a primitive data type in JavaScript?
Array
Object
Function
String
Which value is returned if you compare two distinct objects in JavaScript using the equality (==) operator?
true
false
undefined
NaN
Which of the following keywords is used to declare a variable in JavaScript?
var
let
const
All of the above
What is the scope of a variable declared with the var keyword?
Function scope
Block scope
Global scope only
None of the above
How can you create a constant variable that cannot be reassigned in JavaScript?
const variableName;
constant variableName;
var const variableName;
let const variableName
What will be the output of the following code snippet?
let a = 5;
let b = a;
a = 10;
console.log(b);
(a)
Which method can be used to convert a string to an integer in JavaScript?
parseInt()
toString()
Number()
parseFloat(
What is the data type of null in JavaScript?
(a)
Which of the following is not a primitive data type in JavaScript?
Boolean
Number
Symbol
Array
True or False
In JavaScript, you can change the value of a variable declared with const after it is initialized.
(a)
True or False
The typeof operator can be used to determine the type of a variable.
(a)
True or False
null is strictly equal to undefined in JavaScript.
(a)
In JavaScript, the (a) operator is used to determine the data type of a variable.
Variables declared with let and const have (a) scope.
A variable that is declared but not initialized will have the value (a) .
The (a) function is used to convert a string to a floating-point number.
What will be the output of the following code snippet?
var x = 3;
var y = x;
x - 7;
console.log(y);
(a)
What will be the output of the following code snippet?
const c = 10;
let d = c;
20-d
console.log(c);
(a)
What will be the output of the following code snippet?
let e = 'hello';
let f = e;
e = 'world';
console.log(f);
(a)
What will be the output of the following code snippet?
let arr1 = [1, 2, 3];
let arr2 = arr1;
arr1.push(4);
console.log(arr2);
(a)
What will be the output of the following code snippet?
let obj1 = { a: 1 };
let obj2 = obj1;
obj1.a = 5;
console.log(obj2.a);
(a)
What will be the output of the following code snippet?
let g = [1, 2];
let h = [...g];
g.push(3);
console.log(h);
(a)
What will the following expression evaluate to?
3 + 2 * 2
(a)
Which operator is used to concatenate two strings in JavaScript?
+
&
&&
||
Which of the following operators has the highest precedence?
*
+
-
&&
What will the following expression evaluate to?
4 + 5 + "7"
(a)
Which operator is used to compare both value and type in JavaScript?
==
===
=
!=
What will the following expression evaluate to?
10 % 3
(a)
Which operator is used to increment a variable in JavaScript?
(a)
True or False
The addition operator (+) has a higher precedence than the multiplication operator (*) in JavaScript
(a)
The logical OR operator (||) has lower precedence than the logical AND operator (&&).
(a)
The (a) operator is used to find the remainder of a division operation.
True or False:
The for loop is typically used when the number of iterations is known beforehand.
(a)
In JavaScript, the do...while loop is an example of a (a) loop.
Which of the following methods adds elements to the end of an array?
push()
pop()
shift()
unshift()
True or False:
Arrays in JavaScript can hold elements of different data types.
(a)
Arrays are indexed starting from (a) .
Which method removes the first element from an array and returns it?
shift()
unshift(
pop()
push()
Array.isArray(myArray) returns true if myArray is an array.
True
False
Which method returns the index within the calling String object of the first occurrence of the specified value?
indexOf()
lastIndexOf()
search()match()
In JavaScript, the while loop executes a block of code as long as a specified (a) is true.
Which loop executes a block of code at least once, and then repeats the loop as long as a specified condition is true?
do...while
for...in
while
for
True or False:
break statement is used to terminate the execution of a loop.
(a)
The Math.random() function generates a random number between ... and ....
1 & 5
0 & 1
5 &10
0 & 9
The .map() method modifies the original array.
True
False
Both
No answer
Which method is used to find the length of a string in JavaScript?
length
.length()
length()
All the above
Which method is used to find the length of a string in JavaScript?
length
.length()
length()
All the above
Which of the following methods is used to concatenate two strings?
(a)
What will be the output of the following code?
let str = "Hello, World!";
console.log(str.toUpperCase());
(a)
What does the .includes() method do in JavaScript?
Checks if a string contains a specified value
Finds the index of a value
Splits a string into an array
Replaces a part of a string
What does the .includes() method do in JavaScript?
Checks if a string contains a specified value
Finds the index of a value
Splits a string into an array
Replaces a part of a string
What will be the output of the following code?
let str = "JavaScript";
console.log(str.charAt(4));
(a)
How do you replace "Hello" with "Hi" in a string?
str.replace("Hello", "Hi")
str.change("Hello", "Hi")
str.swap("Hello", "Hi")
str.modify("Hello", "Hi")
Which method is used to split a string into an array?
(a)
What does the break statement do in a loop?
Skips one iteration
Stops the loop completely
Restarts the loop
Throws an error
What does the Math.max(2, 8, 5, 10, 3) function return?
(a)
Which of the following is NOT a valid DOM collection type?
ElementArray
All are valid
HTMLCollection
NodeList
Which property returns the number of child elements a DOM element has?
childElementCount
childNodes.length
children.count
element.childCount
What is the purpose of querySelectorAll()?
To select all elements matching a CSS selector
To create new DOM elements
To remove elements from the DOM
To select a single element
Which property is used to modify the CSS styles of a DOM element?
Which method returns a collection of elements with a specific class name?
document.getElementsByClassName()
document.querySelectorAll()
document.getElementById()
document.getElementsByTagName()
What does DOM stand for?
(a)
Which keyword is used to wait for a Promise to resolve inside an async function?
wait
yield
await
pause
What is the primary advantage of asynchronous programming in JavaScript?
It prevents blocking the main thread
It executes code sequentially
It makes all operations synchronous
It reduces code complexity
Which of the following correctly defines a function using a function declaration?
function myFunc() {}
function: myFunc() {}
var myFunc = () => {}
def myFunc() {}
How do you create an instance of a class?
What is the purpose of the extends keyword in a JavaScript class?
To define a static method
To inherit from a parent class
To bind methods permanently
To encapsulate private properties
How do you properly write a while loop?
while (i < 10) {}
while { i < 10 }
while i < 10 {}
while i = 10 {}
