Prepare for the Salesforce JavaScript Developer Exam. Utilize comprehensive quizzes, flashcards, and multiple choice questions with hints and explanations. Boost your exam readiness!

Practice this question and more.


What is the value of the variable sum defined with eval?

  1. 105

  2. "105"

  3. TypeError

  4. "10*10+5"

The correct answer is: 105

When using `eval`, the code inside the string is executed as if it were actual JavaScript code. In this case, if the variable `sum` is defined using `eval` to evaluate the expression `"10*10+5"`, the expression is computed by the JavaScript engine. Here's the breakdown of the evaluation: 1. The string expression `"10*10+5"` is parsed. 2. The multiplication precedes addition according to operator precedence rules in JavaScript. 3. Therefore, `10 * 10` is evaluated first, resulting in `100`. 4. Then, `5` is added to `100`, yielding a final result of `105`. As a result, if the variable `sum` is assigned the value of this evaluated expression, its value will indeed be `105`, a number, not a string. This is why the chosen answer reflects the numeric value resulting from the evaluated expression correctly.