Worksheetstest1
Total questions: 10
Worksheet time: 5mins
What is the output of the following code: if (5 > 3) { console.log('A'); } else { console.log('B'); }?
C
B
A
D
How many times will the loop run: for (let i = 0; i < 5; i++) { console.log(i); }?
6
10
5
4
What will be the output of the following while loop: let i = 0; while (i < 3) { console.log(i); i++; }?
3
0 1 2
5
4
Given the string 'Hello World', how would you access the character 'W'?
string[4]
string[6]
string[7]
string[5]
What is the result of the following array operation: let arr = [1, 2, 3]; arr.push(4);?
[1, 2, 3]
[1, 2, 3, 4]
[1, 2, 3, 4, 5]
[4, 1, 2, 3]
How do you declare a function in JavaScript that takes two parameters and returns their sum?
function total(a, b) { return a * b; }
function calculate(a, b) { return a / b; }
function add(x, y) { return x - y; }
function sum(a, b) { return a + b; }
What is function overloading and how is it implemented in languages that support it?
Function overloading is a method to create functions with unique names for different tasks.
Function overloading allows functions to be defined only once with fixed parameters.
Function overloading is a technique to combine multiple functions into a single function call.
Function overloading is a feature that allows multiple functions with the same name to coexist, differentiated by their parameter types or counts.
How can you concatenate two strings in JavaScript?
string1 + string2 or string1.concat(string2)
string1 & string2
string1 * string2
string1 - string2
What will be the output of the following code: let arr = [1, 2, 3]; console.log(arr[1]);?
1
undefined
2
3
Explain the difference between a for loop and a while loop in programming.
A for loop iterates a known number of times, while a while loop continues until a condition is false.
A for loop requires a condition, while a while loop does not need any condition.
A for loop is used for conditional checks, while a while loop is for fixed iterations.
A for loop runs indefinitely, while a while loop stops after a set number of iterations.
