String and Number Conversion in JavaScript
var myString = "999";
// Convert String to a number
var myNumber = +myString; // → 999
// OR
var myNumber = Number(myString) // → 999
// Convert String to negative number
var myNegativeNumber = -myString; // → -999
// OR
var myNegativeNumber = -Number(myString) // → -999
Comments
Post a Comment