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

Popular posts from this blog

Inserting and Moving elements inside Ruby Array

Interview Question on Ruby on Rails