menu

JavaScript Conditional Statements


1.

What is the output of the following code?

var x = 10;
var y = "10";
if (x === y) {
console.log("x is equal to y");
} else {
console.log("x is not equal to y");
}

x is equal to y

x is not equal to y

undefined

Error


2. Which of the following is the correct syntax for a switch statement in JavaScript?

switch (x) {

switch (x == 10) {

switch x {

switch (x === "10") {


3. Which of the following is a falsy value in JavaScript?

0

undefined

{}

1


4. Which of the following is a logical operator in JavaScript?

+

/

&&

%


5.

What is the value of x after the following code is executed:

var x = 10;
if (x < 5) {
x = x + 5;
} else if (x < 15) {
x = x + 10;
} else {
x = x + 15;
}
console.log("Value of x is", x);

15

20

25

30


6. Which of the following is a truthy value in JavaScript?

0

null

0

hello


7.

What is the output of the following code?

var x = "10";
var y = 10;
if (x == y) {
console.log("x and y are equal");
} else {
console.log("x and y are not equal");
}

x and y are equal

x and y are not equal

10 and 10 are equal

No output


8.

What is the output of the following code?

var x = 10;
var y = 20;
var z = x > y ? "x is greater than y" : "y is greater than x";
console.log(z);

x is greater than y

y is greater than x

undefined

Error


9.

What is the output of the following code?

var x = "10";
var y = 10;
if (x === y) {
console.log("x and y are equal");
} else {
console.log("x and y are not equal");
}

x and y are equal

x and y are not equal

10 and 10 are equal

No output


10. What is the purpose of the break statement in a switch statement?

To exit the switch statement

To execute the next case

To define a new case

To execute a default case