I am getting id
from URL like this. Both are object
. If I recognize it like id[0]
then it gives me datatype String
But as a human I can understand one is String
and another is Integer
.
How can I recognize it with JS Code?
I am getting id
from URL like this. Both are object
. If I recognize it like id[0]
then it gives me datatype String
But as a human I can understand one is String
and another is Integer
.
How can I recognize it with JS Code?
Try to parse as an integer:
function roughScale(x, base) {
const parsed = parseInt(x, base);
if (isNaN(parsed)) { return 0; }
return parsed * 100;
}
console.log(roughScale(' 0xF', 16));
// expected output: 1500
console.log(roughScale('321', 2));
// expected output: 0
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt