0 votes
in JavaScript by
Among the following given JavaScript snipped codes, which is more efficient:

Code A

for(var number=10;number>=1;number--)  

{  

document.writeln(number);  

}  

Code B

var number=10;  

while(number>=1)  

{  

document.writeln(number);  

       number++;  

}  

a) Code 1

b) Code 2

c) Both Code 1 and Code 2

d) Cannot Compare

1 Answer

0 votes
by

Answer: A

Reason: Code 1 will be more efficient. In fact, the second code may encounter a runtime error because the value of "number" is never going to be equal to or less than one.

Related questions

0 votes
asked Mar 21, 2021 in JavaScript by rajeshsharma
0 votes
asked Mar 20, 2021 in JavaScript by sharadyadav1986
...