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

+1 vote

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

0 votes

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:

- NCERT Class 12 Maths Solutions
- NCERT Class 12 Physics Solutions
- NCERT Class 12 Chemistry Solutions
- NCERT Class 12 Biology Solutions
- NCERT Class 10 Science Solutions
- NCERT Class 10 Maths Solutions

- CBSE Class 12 Maths Questions Answers
- CBSE Class 12 Physics Questions Answers
- CBSE Class 12 Chemistry Questions Answers
- CBSE Class 12 Biology Questions Answers
- CBSE Class 10 Science Questions Answers
- CBSE Class 10 Maths Questions Answers

- JEE Crash Course Questions & Answers
- NCERT Course Questions and Answers
- CBSE Board Questions Bank
- ICSE Board Questions Bank
- Free Study Materials
- Question & Answers Bank for All Classes
- Text Book Solutions
- Previous Year Question Paper