What is the output of the following code snippet when logged to the console? let num = 10; const increaseNumber = () => num++; const increasePassedNumber = number => number++; const num1 = increaseNumber(); const num2 = increasePassedNumber(num1); console.log(num1); console.log(num2);

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

The correct output of the code snippet relates to how the variables and functions interact in JavaScript, particularly in regards to the concepts of variable scope and return values.

Initially, num is set to 10. The increaseNumber function increments num by 1 each time it's called and returns the original value of num before the increment occurs. So when increaseNumber() is invoked, it increases num from 10 to 11 but returns 10. This value, which is 10, is assigned to num1.

Next, increasePassedNumber is a function that takes a number as an argument and increments that number, returning the original input value before the increment occurs. Here, num1 (which is 10) is passed to this function. It effectively increments the value of number passed to it, so it receives 10, increments it, but returns the original value of 10. This is assigned to num2.

Thus, when logging num1, we get 10 (the value returned by increaseNumber before the increment), and when logging num2, we also get 10 (the value passed to `increasePassedNumber

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy