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

 

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. A) 8 B) 0 C) 9 D) Error...
asked Feb 27, 2021 in Technology by JackTerrance
0 votes
    What is the output of the following expression? function multi(x,y) { var c = x*y; } multi(20,3); 1. 20 2. 60 3. 3 4. Nothing...
asked Feb 25, 2021 in Technology by JackTerrance
0 votes
    What is the output of the following expression? function multi(x,y) { var c = x*y; } multi(20,3); A) 20 B) 60 C) 3 D) Nothing...
asked Oct 9, 2020 in Technology by JackTerrance
0 votes
    Q.32 :-What will the SWAP macro in the following program be expanded to on preprocessing? will the code compile? ... y); return 0; Select the correct answer from above options...
asked Nov 30, 2021 in Education by JackTerrance
0 votes
    In Java, what will be the output of the following code and how? double x=2.9,y=2.5; (SOP is abbreviated form ... x),y)); Explain how Select the correct answer from above options...
asked Nov 28, 2021 in Education by JackTerrance
0 votes
    What is the output for the following function test(x) { while(x < 5) { x++; } return x; } alert(test(2)); 1. 6 2. 3 3. 2 4. 5...
asked Feb 25, 2021 in Technology by JackTerrance
0 votes
    What is the output for the following function test(x) { while(x < 5) { x++; } return x; } alert(test(2)); A) 6 B) 3 C) 2 D) 5 #insurance and Loans...
asked Oct 9, 2020 in Technology by JackTerrance
0 votes
    e)What will be the output of the following code? (2) x,y=4,8 z=x/y*y print(z) Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    1. Predict the output of the following operations if x=5 and y=3. x>=10&& y>=4 f. x>=1 || y>=4 Select the correct answer from above options...
asked Dec 21, 2021 in Education by JackTerrance
0 votes
    dues. Find the output of following A. X = 3 . Y = x + 2 x+ =y print (x,y) a = 5 b = 2xa a+ = a+b b* = a+b print (a,b) ) Select the correct answer from above options...
asked Dec 27, 2021 in Education by JackTerrance
0 votes
    dues. Find the output of following A. X = 3 . Y = x + 2 x+ =y print (x,y) a = 5 b = 2xa a+ = a+b b* = a+b print (a,b) ) Select the correct answer from above options...
asked Dec 26, 2021 in Education by JackTerrance
0 votes
    Two integers xandy are chosen with replacement out of the set {0,1,,2,3,10} . Then find the probability that |x-y ... 25 121 D. 20 121 Select the correct answer from above options...
asked Nov 15, 2021 in Education by JackTerrance
...