Yes, that’s correct. The <· symbol returns the value which the last expression entered evaluates to, even though we aren’t explicitly using the return
keyword. Here is a link to a discussion about this, which I think is helpful, and it also uses a while loop as an example.
https://stackoverflow.com/questions/21820746/chrome-devtools-whats-this-arrow-meaning
The interesting thing to note about the example in the link, is that the final returned value (<· 4
) is the same as the final value logged to the console (4). This is different to our original example, where it was higher: <· 14
(returned) as opposed to 12 (logged).This is because the final expression in our while loop body was num = num + 2
which evaluates to the num
just logged (12) + 2 = 14). However, in the example in the link the final expression in the while loop body is i++
and not ++i
. The position of the increment operator ++
is key because:
- If placed BEFORE the operand (
++i
) the expression is evaluated and its value returned AFTER incrementing (i.e. the example in the link would console.log 4 and return<· 5
; - But when placed AFTER the operand (
i++
) the expression is evaluated and its value returned BEFORE incrementing.
You can read more about the increment operator in MDN Web Docs:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Increment
I hope this fully answers your question, and makes things much clearer for you