Is the following correct? And why?
x = 7;
y = 7.00;
z = x + y;
console.log(z);
Result:
14
I expect the log result to be "14.00".
Is the following correct? And why?
x = 7;
y = 7.00;
z = x + y;
console.log(z);
Result:
14
I expect the log result to be "14.00".
A 99% true statement: There is no "dynamic typing int/float" in JavaScript because there are no ints or floats in JavaScript. console.log
will write the most compact representation. In fact, console.log(7.00)
displays 7
.
The more correct statement: integers are internally available in JavaScript (as result of bit-operations, mostly), but all numbers that reach your program are floats.
Finally, there is no reason why console.log
should display anything to two decimals, unless the most compact representation had two decimals (like 7.23
).