why java script convert string to number when I'am put only + before string
var x = "44";
var y =(+x);
var z = 34 + x;
console.log(typeof y); //number
console.log(typeof z); //string
why java script convert string to number when I'am put only + before string
var x = "44";
var y =(+x);
var z = 34 + x;
console.log(typeof y); //number
console.log(typeof z); //string
From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators:
+
is the Unary operator. It attempts to convert the operand to a number, if it is not already.