I know that addition of number and string concatenates the two inputs in javascript which is completely understandable but string and number addition giving strange output. Please somebody let me know why this is happening.
calculate.js
let fs = require("fs");
let data = fs.readFileSync(0, 'utf-8');
let idx = 0;
data = data.split("\n");
function readLine() {
idx++;
return data[idx - 1];
}
let unitCost = readLine();
console.log(unitCost);
console.log(typeof(unitCost))
let GSTpcnt = readLine();
console.log(GSTpcnt);
console.log(typeof(GSTpcnt));
let tax = GSTpcnt / 100 * unitCost;
console.log(tax);
console.log(typeof(tax));
// let finalCost = tax + unitCost; // number + string ==> 18100
let finalCost = unitCost + tax; //string + number ==> 180
console.log(finalCost);
console.log(typeof(finalCost));
input.txt:
100
18