JavaScript Operators
JavaScript Operators - Important Points
11. | What is the result of true + 2 in JavaScript? |
---|
A. 3
B. 3
C. 1
D. NaN
View Answer Discuss Work SpaceAnswer: option a
Explanation:
When a boolean value is used in a numerical context, true is converted to 1 and false is converted to 0.
12. | What is the result of "2" * "3" in JavaScript? |
---|
A. 6
B. 6
C. 23
D. 5
View Answer Discuss Work SpaceAnswer: option b
Explanation:
When the * operator is used, JavaScript tries to convert both operands to numbers. In this case, "2" and "3" are both converted to the numbers 2 and 3, and the result of the multiplication is 6.
13. | What is the result of "2" + 3 * 4 in JavaScript? |
---|
A. 20
B. 14
C. 212
D. 14
View Answer Discuss Work SpaceAnswer: option c
Explanation:
When multiple operators are used in an expression, JavaScript uses the operator precedence rules to determine the order of evaluation. In this case, the multiplication is performed first, resulting in the value 12. Then, "2" is concatenated with 12 to form the string "212".
14. | What is the result of (2 + 3) * 4 in JavaScript? |
---|
A. 20
B. 25
C. 14
D. 10
View Answer Discuss Work SpaceAnswer: option a
Explanation:
When parentheses are used, the expressions inside the parentheses are evaluated first. In this case, 2 + 3 is evaluated to 5, and then 5 * 4 is evaluated to give the result of 20.
15. | What is the result of true || false in JavaScript? |
---|
A. 1
B. 0
C. 1
D. 0
View Answer Discuss Work SpaceAnswer: option a
Explanation:
The || operator is the logical OR operator. It returns true if either of its operands is true.