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 output of the given code that uses 'use strict'?

  1. 21

  2. undefined

  3. ReferenceError

  4. TypeError

The correct answer is: ReferenceError

The presence of `'use strict'` in the code introduces a stricter syntax for JavaScript, which helps in catching common coding mistakes and "unsafe" actions such as assigning values to undeclared variables. When `'use strict'` is activated, JavaScript stops executing code once it encounters conditions that violate strict mode, leading to various types of exceptions. If the code under examination attempts to access a variable that hasn't been declared properly, the strict mode will throw a `ReferenceError`. This type of error indicates that the code is trying to reference an identifier that does not exist within the appropriate scope. The use of strict mode makes developing JavaScript applications more predictable and easier to debug by providing immediate feedback on such issues. In this case, if the code is trying to access a non-declared variable, enforcing strict mode would indeed lead to a `ReferenceError`, making this the correct output choice. This behavior exemplifies how strict mode enhances the robustness of JavaScript code by enforcing better practices.