Font size
WorksheetsJavaScript Day-1
Total questions: 25
Worksheet time: 17mins
Which symbol is used for single-line comments in JavaScript?
<!-- -->
#
//
/* */
Which function is used to display output in browser console?
print()
log()
console.log()
document.write()
What does the spread operator (...) do in this context? let arr2 = [...arr1, 4, 5];
Creates a nested array
Copies/Expands elements
Deletes elements of arr1
Sorts the array
Which of the following is a correct variable declaration?
int x = 10;
var x = 10;
number x = 10;
x := 10;
let scores = [85, 80, 70, 92, 60];
for (let i = 0; i < scores.length; i++) {
let currentScore = scores[i];
if (currentScore >= 90) {
console.log(`Score ${currentScore}: Grade: A`);
} else if (currentScore >= 80) {
console.log(`Score ${currentScore}: Grade: B`);
} else if(currentScore >= 70){
console.log(`Score ${currentScore}: Grade: C`);
}
else {
console.log(`Score ${currentScore}: Grade: D`);
}
}
Score 85: Grade: A
Score 80: Grade: B
Score 70: Grade: C
Score 92: Grade: A
Score 60: Grade: D
Score 85: Grade: B
Score 80: Grade: B
Score 70: Grade: C
Score 92: Grade: A
Score 60: Grade: D
Score 85: Grade: B
Score 80: Grade: B
Score 70: Grade: C
Score 92: Grade: A
Score 60: Grade: C
Score 85: Grade: B
Score 80: Grade: A
Score 70: Grade: C
Score 92: Grade: A
Score 60: Grade: C
What is the main difference between let and var?
let is function-scoped, var is block-scoped.
let is block-scoped, var is function-scoped.
var cannot be reassigned.
There is no difference.
What does the "Spread Operator" (...) do
Compresses an array into a single value
Expands elements of an array or object
Deletes all elements in an array
Multiplies all numbers in an array
What is the result of the following comparison? 5 === '5'
(a)
Which operator is used to assign a value to a variable?
==
===
=
!=
What is an "Arrow Function" syntax example
function myFunc() {}
let myFunc = () => {}
arrow function myFunc() {}
let myFunc = function() {}
What are "Default Parameters" in ES6?
Parameters that must always be provided.
Values assigned to parameters if no argument is passed during the function call.
A way to name functions.
Variables that only work inside a for loop
The prompt() function always returns __________.
Number
String
Boolean
Object
console.log() is mainly used for (a) .
Which keyword is used to define a function in JavaScript?
function
def
fun
method
Which Set method returns an iterator object containing [value, value] pairs for each element?
(a)
Functions without a name are called (a) functions.
What is the "Ternary Operator" syntax?
condition : true ? false
condition ?? true : false
if (condition) ? true
condition ? value_if_true : value_if_false
How do you check if a specific value exists in a Set object named mySet?
mySet.exists(val)
mySet.contains(val)
mySet.has(val)
mySet.find(val)
Functions created using new Function() are called (a) functions.
Complete the loop syntax to run 5 times: for (let i = 2; (a) ; i++)
What happens if a function does not have a return statement?
(a)
Which input function allows a default value to be displayed?
prompt(message)
prompt(message, default)
alert(message)
confirm(message)
Which syntax is used to create a new Set?
new Set()
{}
[]
Set()
let arr1 = [1, 2];
let arr2 = [...arr1, 4, 5];
console.log(arr2);
function sum(args) {
return args.reduce((acc, val) => acc + val, 0);
}
console.log(sum(arr2)) What will be the output of console ?
[ 1, 2, 4, 5 ]
10
[1, 2, 3, 4, 5]
12
[ 1, 2, 4, 5 ]
12
[1, 2, 3, 4, 5]
10
Write the code to add green to the following Set ? let colors = new Set(['red', 'blue']);
(a)
