3 examples of strings: "I love fish. So do cats." "<b>Hi</b>" "2006"
prompt()) need strings to work, and some commands don't work with strings.
Because strings are usually surrounded by double quotation marks (like the ones around "this"), it causes a problem if you want to have a quotation mark inside the string.
This is not a problem:
var hiswords = "He said he was hungry.";
var hiswords = "He said, "I'm hungry!"";
var hiswords = "He said, \"I'm hungry!\"";The browser will understand that each \" pair indicates an internal quotation mark, not the quotation mark at the beginning or end of the string.
var hiswords = "He said, 'I'm hungry!'";
var x = 2 * 60; var y = 3 + x; // we know that y would equal 123
Converting Numbers to Strings:
Let's assume that numbervar has 10 in it. To convert that to a string, use
var x = String(numbervar);
Converting Strings to Numbers:
Let's assume that stringvar has "2005" in it. To convert that to a number, use
var x = Number(stringvar);
Test if a variable holds a Number or a String