menu

JavaScript Conditional Statements

JavaScript Conditional Statements - Important Points


26. Which of the following is the correct syntax for a ternary operator in JavaScript?

A. x ? y : z;

B. x : y ? z;

C. x ? y, z;

D. x ? y || z;

Discuss Work Space

Answer: option a

Explanation:

The correct syntax for a ternary operator in JavaScript is condition ? value1 : value2.

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

A. To exit the switch statement

B. To execute the next case

C. To define a new case

D. To execute a default case

Discuss Work Space

Answer: option a

Explanation:

The break statement is used to exit the switch statement when a match is found for a particular case.

28.

What is the output of the following code?

var x = 10;
if (x < 5) {
console.log("x is less than 5");
} else if (x < 10) {
console.log("x is less than 10");
} else {
console.log("x is greater than or equal to 10");
}

A. x is less than 5

B. x is less than 10

C. x is greater than or equal to 10

D. No output

Discuss Work Space

Answer: option c

Explanation:

The condition x >= 10 is true, so the else block is executed, which outputs "x is greater than or equal to 10".

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

A. 0

B. null

C. 0

D. hello

Discuss Work Space

Answer: option d

Explanation:

A truthy value is a value that is considered true when evaluated in a Boolean context. In JavaScript, non-empty strings are truthy values.

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

A. 0

B. undefined

C. {}

D. 1

Discuss Work Space

Answer: option b

Explanation:

A falsy value is a value that is considered false when evaluated in a Boolean context. In JavaScript, undefined is a falsy value.


Subscribe for Latest Career Trends
Subscribe Now
Use AI and ChatGPT for Career Guidance

Unlock Your Future

Join Now
Worried for Placements in 2024?

Join FAST TRACK Course

Join Now
Supercharge Your SUCCESS

Join All in One Placement Mock Tests-2024

Join Now