If/Else, Switch
Numbers/Strings
Arrays
Loops
Coding Practice
100

What is the result of evaluating: 


(true && false) || true

true

100

Which keyword is used to declare a variable that cannot be reassigned in JavaScript?

const

100

What is the output of this code?

let arr = [1, 2, 3, 4, 5]; 

for (let i = 0; i < arr.length; i++) {

           if (i === 2) break; 

           console.log(arr[i]);

 }

1 2 

100

What does the 'break' statement do in a loop?

Terminates the loop entirely and continues with the next statement after the loop.

100

What will be the output of the following code?

let x = 10; 

if (x > 5) {

      console.log("Greater");

 }

 else {

      console.log("Less or Equal"); 

}

In range

200

What is the purpose of the 'default' case in a switch statement?

It acts as a fallback if none of the specified case matches occur.

200

Which of the following correctly uses a ternary operator to assign a value?

let result = (x > 5) ? "yes" : "no";

200

What is the correct way to write a JavaScript array?

let colors = ["red", "green", "blue"]

200

How many times will this for loop execute?

for (let i = 0; i < 5; i++) { 

           console.log(i); 

}

5 times (0, 1, 2, 3, 4)

200

What will be the output of the following code?

let x = 10; 

if (x > 5) {

      console.log("Greater");

 }

 else {

      console.log("Less or Equal"); 

}

Greater

300

What is the output of this code?

let age = 20; 

let status = (age >= 18) ? "Adult" : "Minor"; console.log(status);

Adult

300

 What does this string method return?

let str = "Hello World"; 

console.log(str.indexOf("o"));

4

300

What will be logged?

let arr = [3, 1, 4, 1, 5]; 

arr.sort(); 

console.log(arr);

[1, 1, 3, 4, 5]

300

What is the output of this while loop?


let i = 0; 

while (i < 3) { 

      console.log(i); 

       i++; 

}

0 1 2

300

What will be logged?

let arr = [1, 2, 3, 4, 5]; 

for (let i = 0; i < arr.length; i++) {

            if (i === 2) continue; 

            console.log(arr[i]); 

}

1 2 4 5 

400

What will be the output of this code?


let num = 2; 

switch(num) { 

            case 1: 

                      console.log("One"); 

            case 2: 

                      console.log("Two");

            case 3: 

                      console.log("Three"); 

                       break; 

             default: 

                 console.log("Other"); 

}

Two Three

400

 What is the output?

let num = 42.567; 

console.log(num.toFixed(2));

42.5

400

What is the result of this array method?

let arr = [1, 2, 3, 4, 5]; 

let result = arr.filter(function(x) { return x > 2; }); console.log(result);

[3, 4, 5]

400

What will be logged?

let i = 0; 

do {

      console.log(i); 

       i++;

 } 

while (i < 3);

No output

400

What will be logged?

let x = 5; 

if (x > 3 && x < 10) {

             console.log("In range"); 

else { 

              console.log("Out of range"); 

}

In range

500

Which switch statement correctly handles the case where day equals 3?

A. switch(day) {

         case 3: console.log("Wednesday"); 

         default: console.log("Other"); 

}

B. switch(day) {

         case 3: console.log("Wednesday"); 

                  break; 

          default: console.log("Other"); 

       }

C. switch(day) { 

         if (day === 3): 

                  console.log("Wednesday"); 

     }

D. switch(day = 3) { 

             case 3: console.log("Wednesday"); 

             break; 

}

B.

500

What is the result of this string method?

let str = "JavaScript"; console.log(str.substring(0, 4));

Java

500

What will be logged?


let arr = [1, 2, 3, 4];

 let result = arr.reduce(function(sum, x) { return sum + x; }, 0); 

console.log(result);

10

500

What does the forEach method do?


let arr = [1, 2, 3]; 

arr.forEach(function(num) { console.log(num * 2); });

Logs 2, 4, 6 (each element multiplied by 2)

500

concat()

slice()

indexOf()

pop()

joins two or more strings

extracts a part of a string and returns the extracted part in a new string.

searches an array for an element value and returns its position.

removes the last element from an array