Salesforce JavaScript Developer Practice Exam

Session length

1 / 400

What will console.log(number++) and console.log(++number) output for the variable defined as let number = 0?

1 1 2

1 2 2

0 2 2

The output for the expressions `console.log(number++)` and `console.log(++number)` when the variable `number` is defined as `let number = 0` will be `0` for the first log and `2` for the second.

Initially, `number` is set to `0`. When the expression `console.log(number++)` is executed, the current value of `number` (which is `0`) is logged to the console. The post-increment operator (`number++`) increases the value of `number` by `1` after the current value has been returned. Therefore, `0` is printed to the console, and afterward, `number` becomes `1`.

Next, when `console.log(++number)` is executed, the pre-increment operator (`++number`) increases the value of `number` by `1` before it's logged. Since `number` was `1` after the previous operation, it becomes `2` with this pre-increment operation, and then `2` is printed to the console.

Thus, the final sequence of outputs is `0` (from the post-increment) followed by `2` (from the pre-increment), which fits the output from the

Get further explanation with Examzify DeepDiveBeta

0 1 2

Next Question
Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy