1D0-735 practice question 4 of 15

Which of the following comparison statement will return true? A) X=10; Y=11; y--; x==y B) X=10; Y=11; Y++; x==y’ C) X=11; Y=10; y--; x==y; D) X=11; Y=10; y-= 1; x==y

Full set: 55 questions
Answer options
A: Option A Correct answer
B: Option B
C: Option C
D: Option D
Correct Answer:
A. Option A
Explanation

This question tests the understanding of JavaScript's decrement operator and equality comparison. In option A, the variable x is assigned the value 10, and y is assigned 11. The statement y-- is a post-decrement operation, which subtracts 1 from the current value of y. This changes y's value from 11 to 10. The final comparison x == y then evaluates 10 == 10, which correctly returns true. All other options result in a final comparison that evaluates to false.

Why Incorrect

In option B, y is incremented to 12. The comparison 10 == 12 is false. In option C, y is decremented to 9. The comparison 11 == 9 is false. In option D, y is reduced to 9. The comparison 11 == 9 is false.

References

1. ECMAScript® 2023 Language Specification (ECMA-262, 14th edition):

Section 13.4.5 Update Expressions: Defines the behavior of the decrement (--) operator. It specifies that the operation subtracts the value 1 from its operand.

Section 13.11 Equality Operators: Describes the IsLooselyEqual abstract comparison algorithm used by the == operator, which for two operands of the Number type, performs a direct numerical comparison.

2. Mozilla Developer Network (MDN) Web Docs:

Decrement (--) Operator: "The decrement (--) operator decrements (subtracts one from) its operand... If used postfix (for example, x--), the decrement operator decrements and returns the value before decrementing." The side effect is that the variable's stored value is reduced by one.

Equality (==) Operator: "The equality (==) operator checks whether its two operands are equal, returning a Boolean result."

3. W3Schools JavaScript Tutorial (Referenced by many university curricula):

JavaScript Arithmetic Operators: The page on arithmetic operators explains that -- is the decrement operator, which subtracts one from a variable's value.

JavaScript Comparison Operators: The page on comparison operators confirms that == checks for equal value.

Scroll to Top