0

1. How is var a = 9? in this Javascript Challenge.I thought the increement is to happen after the substraction.

Fill in the blank to output 3. var a = ; var b = 5; b++; alert(a - b) 2. What number will output 3, if b++ is substituted with ++b.

22nd Jan 2024, 6:05 AM
Dr Melchisedec Bankole
Dr Melchisedec Bankole - avatar
3 Respostas
+ 5
The 3rd statement, b++, is a standalone statement which increase b by 1. Even if it is written in ++b, it does the same thing because it is a complete statement. Therefore, before alert b is equal to 6, and 9 minus 6 equals to 3. I put them into this code so you can see the action. https://sololearn.com/compiler-playground/WFMJicdwt5H7/?ref=app
22nd Jan 2024, 6:14 AM
Wong Hei Ming
Wong Hei Ming - avatar
+ 4
Dr Melchisedec Bankole , For the increment to happen after the subtraction, you'd have to write it like this. alert(a - b++)
22nd Jan 2024, 6:13 AM
Rain
Rain - avatar
+ 3
Code executes step by step so not possible of increment after substraction.
22nd Jan 2024, 6:41 AM
A͢J
A͢J - avatar