Edit in JSFiddle

//Type Coercion

var x = "123 ABC"; //string
var y = "53.29"; //string
var z = "ABC 123"; //string

var a = 12345; //number
var b = 34.34; //number
var c = "1234.45 789 098 Hello"; //string 
var d = true; //boolean

x = parseInt(x);

console.log("x is of type " + typeof(x));
console.log("y is of type " + typeof(parseFloat(y)));
console.log("z is of type " + typeof(parseInt(z)));
console.log("a is of type " + typeof(String(a)));
console.log("b is of type " + typeof(String(b)));
console.log("c is of type " + typeof(parseFloat(c)));
console.log("d is of type " + typeof(String(d)));
<!-- Easy JavaScript #10 - Intro Type Coercion -->
JavaScript is a weakly typed scripting language. It means that the variable type can be changed in certain circumstances. This is known as Type Coercion. 
If we have the string "10", we can easily coerce this value to be seen as a number, or integer 10 by using either parseInt() or parseFloat(). 
If we have a number 1234567, we can coerce this value to be seen as a string, either by using String() or by putting quotes around it and writing "1234567" instead. 
You can even turn a boolean, true, into a string! Try String(true);! It's often easier to turn some other variable type into a string than it is to turn a string into something else. 
Rules of parseInt and parseFloat:
<li>Only the first number in a string is parsed.</li>
<li>Although Spaces are allowed, only the first number will be parsed.</li>
<li>If the first character can't be coerced, then it can't be converted!</li>
Visit <a href="http://www.easyprogramming.net">EasyProgramming.net</a> for more tutorials!