in Technology by

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

 

Please log in or register to answer this question.

2 Answers

0 votes
by

Answer:-10,11

0 votes
by

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

0 votes
    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? 1. 10,11 2. 10,10 3. 11,10 4. 11,11...
asked Feb 23, 2021 in Technology by JackTerrance
0 votes
    Predict the output of the following JavaScript code.
...