A technician is troubleshooting a custom JavaScript (`.js`) automation script used to audit network workstation licenses. The script includes the line `let activeLicenses = "45";` and later attempts to update the count using `activeLicenses = activeLicenses + 5;`. When executed, the script outputs `455` instead of `50`. Which of the following identifies the root cause of this output?
- The variable was declared as a string data type instead of an integer, causing the addition operator to concatenate the values.Answer
- BThe variable was initialized as an environment variable rather than a standard script variable, preventing arithmetic evaluation.
- CThe script requires a conditional `FOR` loop construct to iterate over numerical variable assignments.
- DThe script interpreter requires the `/a` command-line switch to enable mathematical calculation mode.
Answer
The variable was declared as a string data type instead of an integer, causing the addition operator to concatenate the values.
Enclosing values in quotation marks defines them as string data types. When performing addition with a string operand in JavaScript, the interpreter converts numbers to text and concatenates them (e.g., '45' + 5 = '455'). To perform arithmetic addition, the variable must be defined as an integer without quotation marks.
Step-by-Step Solution
Key Concept
Scripting Data Types (Strings vs. Integers)