+1 vote
55 views
in Technology by (230k points)

Code A: var x = 10; y = --x + 1;
alert(y);
Code B: var x = 10;
y = x-- + 1;
alert(y);
What is the output for code A and B?
a)10,11
b)10,10
c)11,10
d)11,11

 

2 Answers

0 votes
by (230k points)

Answer:-10,11

0 votes
by (51.6k points)

JavaScript programs may generate unexpected results if a programmer accidentally uses an assignment operator (=), instead of a comparison operator (==) in an if statement.

This if statement returns false (as expected) because x is not equal to 10:

Addition is about adding numbers.

Concatenation is about adding strings.

In JavaScript both operations use the same + operator.

Because of this, adding a number as a number will produce a different result from adding a number as a string:

Related questions

+1 vote
1 answer 159 views
0 votes
1 answer 47 views
0 votes
0 answers 65 views
0 votes
1 answer 15 views
0 votes
1 answer 19 views
asked Oct 8, 2020 in Technology by JackTerrance (230k points)
...