• Tutorials
  • Courses
  • Tracks

JavaScript | Control Flow 2

Last Updated :
Discuss
Comments

Question 1

What will be the output of the following code?

JavaScript
let y = 10;
if (y == "10") {
    console.log("Equal");
} else {
    console.log("Not equal");
}


  • Equal

  • Not equal

  • Both "Equal" and "Not equal"

  • No output

Question 2

Can the ternary operator be used inside a function?

  • Yes, always.

  • No, never

  • Only if the function returns a value.

  • Only if the function has no parameters.

Question 3

What happens if the break statement is missing in a switch case?

  • The execution will continue to the next case.

  • The program will throw an error.

  • The switch statement will not work.

  • Nothing, it's optional.

Question 4

What will be the output of the following code?

JavaScript
let z = 0;
if (z) {
    console.log("True");
} else {
    console.log("False");
}


  • True

  • Both "True" and "False"

  • False

  • No output

Question 5

What will be the output of the following code?

JavaScript
let grade = 'B';
switch (grade) {
  case 'A':
    console.log("Excellent");
    break;
  case 'B':
  case 'C':
    console.log("Good");
    break;
  default:
    console.log("Poor");
}


  • Good

  • Excellent

  • Poor

  • Error

Question 6

What will be the output of the following code?

JavaScript
let a = 5;
if (a > 3) {
    if (a < 7} {
        console.log("Between 3 and 7");
    }
}


  • Between 3 and 7

  • No output

  • Undefined

  • Error

Question 7

Is it possible to have a switch statement without any case clauses?

  • Yes, but it will do nothing.

  • No, a switch must have at least one case.

  • Yes, but only if there is a default case.

  • No, it will cause a syntax error.

Question 8

Which of the following will output "Positive"?

  • JavaScript
    let num = -5; console.log(num > 0 ? "Positive" : "Negative");
    


  • JavaScript
    let num = 5; console.log(num > 0 ? "Positive" : "Negative");
    


  • JavaScript
    let num = 0; console.log(num > 0 ? "Positive" : "Negative");
    


  • JavaScript
    let num = 10; console.log(num < 0 ? "Positive" : "Negative");
    


Question 9

What will be the output of the following code?

JavaScript
let b = 12;
if (b > 5) {
    console.log("Greater than 5");
} else if (b > 10) {
    console.log("Greater than 10");
} else {
    console.log("Less than or equal to 5");
}


  • Greater than 5

  • Greater than 10

  • Less than or equal to 5

  • No output

Question 10

What is the output of the following code?

JavaScript
let day = 3;
let message = day === 1 ? 'Start of the week' : day === 2 ? 'Second day' : day === 3 ? 'Midweek' : day === 4 ? 'Almost weekend' : 'Weekend';
console.log(message);


  • Start of the week

  • Second day

  • Midweek

  • Weekend

There are 10 questions to complete.

Take a part in the ongoing discussion