The data in your JavaScript programs can be of many different types. For example, you might have some textcalled a text string that you want to display, like this: document.write("Hello, welcome to my Web page!") Or you might be writing a compound interest calculator for users and need to keep in mind the interest rate, the amount the user has invested, and the length of time the user wants to collect interest for to be able to calculate what he wants to know. Or you might even have a database of items to sell and need to search that database for matches to what the user is looking for. To make your programs actually do something, you won't get very far without being able to handle some data and work on it. Internally, JavaScript has several data types it uses. For example, the string data type lets JavaScript handle strings of text, the number data type lets JavaScript handle numeric values, and so on. Here are the different data types that JavaScript supports internally:
You can use data of these various types in two ways in your code. First, you can embed it directly in JavaScript statements, like this: document.write("Hello") document.write(3.1415926) These directly embedded data items are called literals , they're values that appear in your code statements. Here, I'm writing the string "Hello" and the number 3.1415926 to a web page and storing those values as literals in the code. The second way to store data is to use variables , and I'll take a look at working with variables now. |