0

//enter the value of x

var x=prompt("Enter the value of x:");

//x=x+1 x=x+1;

alert(x);

input

output

Rajkumar
  • 1
  • 1
  • because x is a string – GrafiCode May 26 '22 at 11:20
  • i write x++ it produe correct result.but write x=x+1 only it produce wrong result.... – Rajkumar May 26 '22 at 11:24
  • the increment operator (++) automatically converts the value to a number. I didn't find any detail about it on MDN, but you can see it in ECMAScript specifications: https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-postfix-increment-operator – GrafiCode May 26 '22 at 11:25
  • this line of pseudo code `2. Let oldValue be ? ToNumeric(? GetValue(lhs)).`, I'm pretty sure `ToNumeric` casts the string value to a number. – GrafiCode May 26 '22 at 11:26
  • var x=prompt('Enter the number'); var num1 = parseInt(x); num1+=5; alert(num1); – Rajkumar May 26 '22 at 11:58

0 Answers0