Question about converting datatypes

hey guys, so im going through ASDG, page by page, and learning everything from scratch. he’s explaining datatypes, i.e. strings, numbers, booleans, arrays, etc…i get that. then he goes into explaining how to convert datatypes from numbers to strings using “toString” , and then strings to numbers using “Number()”…and then later, strings to booleans and stuff. My question is this. could some one please explain to me a situation where someone would want to turn a number into a string or a string into a number?and how would someone even turn a string into a number? i dont understand how that works.

well, i can tell you that in the case of using switch (case) the ability to convert to a number is infinitely useful. like in some programs i have did, you can have a user input 1, 2, 3, or 4 (as a string) and then you can parse that into a number that can used in something like :


switch (parse)
case 1:
// do this
break;

case 2:
// do this
break;

that is one example i have ran across where it is useful. not to say that this would not work with the “parsed” as a string (i have never tried it), but converting it to a number is a good safeguard.

just my $.02.

Maybe (like maximum_flash said) you make a webpage where you can calculate foreign currenties. The values that comes through POST are strings, so you have to convert them to number to do the calculation.

what does “parse” mean?

parse is a fancy way to say format.

i see, well, thats a little more helpful. im still having a hard time wrapping my head around it. can any of you explain what the Number(radix) thing is all about?