Q:

Javascript: Converting String to Number?

Is there any way to convert a variable from string to number?
For example, I have
var str = "1";

Can I change it to
var str = 1;

A:

Try str = parseInt( str, 10 )
(note: the second parameter signifies the radix for parsing; in this case, your number will be parsed as a decimal)
That being said, however, the term "type" is used quite loosely in JavaScript.
Could you explain why are you concerned with variable's type at all?

A:

There are three ways to do this:
str = parseInt(str, 10); // 10 as the radix sets parseInt to expect decimals

or 
str = Number(str); // this does not support octals

or
str = +str; // the + operator causes the parser to convert using Number

Choose wisely :)

A:

The best way:
var str = "1";
var num = +str; //simple enough and work with both int and float

You also can:
var str = "1";
var num = Number(str); //without new. work with both int and float

or
var str = "1";
var num = parseInt(str,10); //for integer number
var num = parseFloat(str); //for float number

DON'T:
var str = "1";
var num = new Number(str);  //num will be an object. typeof num == 'object'

Use parseInt only for special case, for example
var str = "ff";
var num = parseInt(str,16); //255

var str = "0xff";
var num = parseInt(str); //255

