node.js - Why does passing '1.0' to a function change it to '1' in javascript -
can explain me why when pass 1.0 function in javascript gets converted 1 , how work around quirk?
var return_me = function(value) { return value; } console.log("1.0 returned " + return_me(1.0));
in javascript there 6 build in types of values.
- string
- number
- boolean
- null , undefined
- object
- symbol
these mentioned book you don't know js find useful in effort learn javascript.
as result js sees var value of function typeof number , understands 1.0 same 1. (in case 1.0 1.9 returns 1.9 expected).
now if want keep these decimals (even if there 0 digits) pass value string.
console.log("1.0 returned " + return_me("1.0"));
Comments
Post a Comment