I was trying to add two text box fields values in Java script. Below is my code
<!DOCTYPE html>
<html>
<head>
<script>
function addFunction() {
var x = document.getElementById("firstInput").value;
var y = document.getElementById("secondInput").value;
var sum=x+y;
alert('Sum is:'+sum);
}
</script>
</head>
<body>
<input type="text" id="firstInput"><br/>
<input type="text" id="secondInput"><br/>
<input type="button" value="Add" onclick="addFunction()">
</body>
</html>
I was expecting the result will be sum of two field values but it is not I entered 2 in first text field and 3 in second text field out put is
Sum is:23
Then only for testing I have added below code in addFunction()
var a = 0.0343;
var b = 0.11;
var x = a + b;
alert(x);
output is
0.144299999999999998
What's going on. Can someone explain me why I am getting these two peculiar output?