I figure the image would be appropriate for south Africans even though the image is from the Netherlands but thats nether here or there.
ANYWAY
Talking more JavaScript here, a developer may been in a situation where one is needing to change types of a certain variables. This is called type conversion. At times you may be in a position to change a type of variable to get a certain function to execute.
The two ways I know how how to cast a string to a number are the following:
var year = '1985'; // set to string
// for interest or certain validation you can
// use typeof to verify the type,
// will be doing this for the examples below:
console.log(typeof year, year);
// expected output: string 1985
// Variable year has been set to a string now for the magic
// option 1: Casting
console.log(typeof Number(year), Number(year));
// expected output: number 1985
// option 2: Method
console.log(typeof parseInt(year), parseInt(year));
// expected output: number 1985
Lets say you want to change a number into a string, that is also possible using casting as well as the toString() function.
var year = 1985; // declared as a number
// Using typeof to verify the type same as above sample
// will be doing this for the examples below:
console.log(typeof year, year);
// expected output: number 1985
// Variable year has been set to a string now for the magic
// option 1: Casting
console.log(typeof String(year), Number(year));
// expected output: string 1985
// option 2: Method
console.log(typeof (year).toString(), (year).toString);
// expected output: string 1985
That is all for today.