CRT-600 practice question 21 of 30
Refer to the expression below: Let x = (‘1’ + 2) == (6 * 2); How should this expression be modified to ensure that evaluates to false?
Full set: 223 questionsThe original expression (‘1’ + 2) == (6 2) evaluates to true. The left side (‘1’ + 2) performs string concatenation, resulting in the string '12'. The right side (6 2) performs multiplication, resulting in the number 12. The loose equality operator == coerces the string '12' to a number, making the comparison 12 == 12, which is true.
Option A, (‘1’ + ‘ 2’) == ( 6 2), correctly modifies the expression to evaluate to false. The left side now concatenates two strings, '1' and ' 2', resulting in the string '1 2'. The right side is still the number 12. The comparison '1 2' == 12 evaluates to false because the string '1 2' (with a space) cannot be coerced into the number 12.
B. Let x = (‘1’ + 2) == ( 6 2);
This is identical to the original expression and therefore evaluates to true, not false.
C. Let x = (1 + 2) == ( ‘6’ / 2);
The left side evaluates to the number 3. The right side coerces '6' to a number for division, also resulting in 3. The expression 3 == 3 is true.
D. Let x = (1 + 2 ) == ( 6 / 2);
Both sides perform arithmetic operations, resulting in the number 3. The expression 3 == 3 is true.
1. Salesforce Lightning Web Components Developer Guide: The guide specifies that LWC uses modern JavaScript (ECMAScript). The behavior of operators like + and == is governed by JavaScript standards.
Source: Lightning Web Components Developer Guide
"JavaScript" section.
2. ECMAScript® 2024 Language Specification (ECMA-262): The official standard for JavaScript defines the behavior of operators.
Section 13.10.3
The Abstract Equality Comparison Algorithm: This section details how == performs type conversion. When comparing a String and a Number
it attempts to convert the String to a Number. ToNumber("12") yields 12
but ToNumber("1 2") yields NaN (Not-a-Number)
and NaN == 12 is false.
Section 13.15.2
The Addition operator (+): This section specifies that if either operand is a string
string concatenation is performed.
3. Apex Developer Guide: While the syntax is JavaScript-like
Apex exhibits similar behavior with string concatenation.
Source: Apex Developer Guide
"Expressions
" "Expression Operators." The + operator is overloaded to perform string concatenation if one of the operands is a String. For example
'Contact' + c results in a string.
Keep practicing
Take the free CRT-600 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other CRT-600 practice questions
- Question 2A developer has the function, shown below, that is called when a page loads. function onl…
- Question 3A developer needs to test this function: 01 const sum3 = (arr) => ( 02 if (!arr.length) r…
- Question 4Refer to the code below: Const resolveAfterMilliseconds = (ms) => Promise.resolve ( setTi…
- Question 10Refer to the following code block: class Animal{ constructor(name){ this.name = name; } m…
- Question 11A developer needs to debug a Node.js web server because a runtime error keeps occurring a…
- Question 12Refer to the string below: const str = 'Salesforce'; Which two statements result in the w…
