menu

JavaScript Conditional Statements

JavaScript Conditional Statements - Important Points


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

A. &&

B. ||

C. !

D. All of the above

Discuss Work Space

Answer: option d

Explanation:

&&, ||, and ! are all logical operators in JavaScript. They are used to combine or negate Boolean values.

17.

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");
}

A. x is equal to y

B. x is not equal to y

C. undefined

D. Error

Discuss Work Space

Answer: option a

Explanation:

The == operator performs type coercion if necessary, so x is considered equal to y even though they are of different types.

18.

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");
}

A. x is equal to y

B. x is not equal to y

C. undefined

D. Error

Discuss Work Space

Answer: option b

Explanation:

The === operator performs strict equality checking and does not perform type coercion, so x and y are not considered equal even though they have the same value.

19.

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);

A. x is greater than y

B. y is greater than x

C. undefined

D. Error

Discuss Work Space

Answer: option b

Explanation:

The ternary operator (?:) is used to assign a value to z based on the result of the condition x > y. Since the condition is false, the value "y is greater than x" is assigned to z.

20. Which of the following is not a valid way to declare a variable in JavaScript?

A. var x;

B. let x;

C. const x;

D. int x;

Discuss Work Space

Answer: option d

Explanation:

int is not a valid keyword for declaring variables in JavaScript. The correct keywords are var, let, and const.


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