Fun With Javascript: Changing Data Types Logo

Javascript Data Types

Before we start changing data types, here's a little background from Learning Javascript by Shelley Powers:

Variables in JavaScript are basically named buckets of data, a way of creating a reference to that data—regardless of whether the data is a string, number, boolean, array, or other object—so that you can access the same data again and again. More importantly, you can use variables to persist data from one process to another. For instance, your JavaScript application can store the value of a form element in a variable, and manipulate that value without having to actually manipulate the form element itself.

Changing Data Types Using the Typeof Operator

The lines below are the result of a script that assigns different data types to a variable and prints the variable's data type. This is accomplished using the typeof operator, and a good deal of aspirin. Did I do it correctly? I am not sure, but I took my best stab at it!