Click here to Skip to main content
15,918,275 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
if (x === 0) {
y = y + 2;
console.log(y);
}
else {
y = y + 3;
console.log(y);
}

What I have tried:

Quote:
if (x === 0) {
y = y + 2;
console.log(y);
}
else {
y = y + 3;
console.log(y);
}
Posted
Updated 7-Jan-21 23:42pm

That's not Java, it looks Javascript.
I wonder why do you think you need to optimize such a piece of code. It works well as it stands.
 
Share this answer
 
Well, you could try:
Java
y += (x === 0) ? 2 : 3;
console.log(y);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900