You're concatenating strings rather than adding numbers, to avoid that, you can remove anything different than a number (i.e: using regex) and then execute the add operation. Further, you need to convert the operands as numbers.
To convert the operands as numbers, you can use either the object Number or simply prefix them with +.
Prefixing with +
var position = "340px";
var end_position = "4px";
var final = +position.replace(/[^\d]/g, '') + +end_position.replace(/[^\d]/g, '') + 'px';
console.log(final)
Using the object Number
var position = "340px";
var end_position = "4px";
var final = Number(position.replace(/[^\d]/g, '')) + Number(end_position.replace(/[^\d]/g, '')) + 'px';
console.log(final)