CRT-600 practice question 24 of 30

Refer to the code below: function changeValue(param) { Param =5; } Let a =10; Let b =5; changeValue(b); Const result = a+ “ - ”+ b; What is the value of result when code executes?

Full set: 223 questions
Answer options
A: 10 -10
B: 5 -5
C: 5 - 10
D: 10 - 5 Correct answer
Correct Answer:
D. 10 - 5
Explanation

In JavaScript, primitive data types like numbers are passed to functions by value. When changeValue(b) is called, a copy of the value of b (which is 5) is passed as the param argument. The function then attempts to assign 5 to a variable named Param. Due to JavaScript's case-sensitivity, Param is a different variable from the parameter param. Therefore, the assignment inside the function does not affect the original variable b in the outer scope. The value of b remains 5. The final expression concatenates a (10), the string " - ", and b (5), resulting in the string "10 - 5".

Why Incorrect

A. 10 -10: This is incorrect because the variable b is never reassigned to 10. The function call does not modify its value.
B. 5 - 5: This is incorrect because the variable a is initialized to 10 and is never modified.
C. 5 - 10: This is incorrect as neither a nor b are changed to these values.

References

1. Mozilla Developer Network (MDN) Web Docs

Functions: "Primitive parameters (such as a number) are passed to functions by value; the value is passed to the function

but if the function changes the value of the parameter

this change is not reflected globally or in the calling function." (See the section on "Passing parameters").

2. Mozilla Developer Network (MDN) Web Docs

Lexical grammar: "JavaScript is a case-sensitive language. This means that language keywords

variables

function names

and other identifiers must always be typed with a consistent capitalization of letters." (See the section on "Case sensitivity").

3. Salesforce Lightning Web Components Developer Guide

JavaScript Considerations: The guide specifies adherence to modern JavaScript (ECMAScript). Core principles like pass-by-value for primitives and case-sensitivity are fundamental to the JavaScript used in Lightning Web Components

which is a key topic in CRT-600. The documentation consistently relies on these standard language features.

Scroll to Top