+ 1
What is the output and why
var x=10; var y; ++x; document.write(x) And what will be output when y = (++x) + (++x) document.write(y)
1 Answer
+ 6
Prefix increment operator works similarly in most languages. The value of the target variable is incremented, and then returned.
x = 10;
++x; // 11
It would be a good idea to use the search bar since how they work has been a frequent topic.
https://www.sololearn.com/Discuss/407846/?ref=app
While prefix/postfix operators are easy to understand, placing multiple instances of them on the same line of operation can be confusing, especially when the behaviour is not properly defined in some languages. I advise against writing code like the example you provided. If you just want to view the output, pasting the code in Code Playground is always an available option.
var x = 10
console.log(++x + ++x)
outputs 23 for me. Even if you can deduce the logic behind the result, this value will vary from language to language.