Exercise Weekend

Goal: In the Data Types lesson, we learned:

  • 5 data types - number, string, boolean, undefined, null
  • Methods are generally specific to a data type
  • How to use typeof to check data type
  • How to use parseInt() and .toString() to convert between numbers and strings

Explore these different data types and their corresponding methods by completing the exercises listed below.

Warm Up


  • What data type is NaN? What about Infinity?
  • How do we tell what data type something is?
  • Name one way to convert something of one data type into another data type.

Code


Data Types Practice

Practice checking and converting data types by doing the following:

  • Set a variable equal to your favorite number and check the data type.
  • Then, create a new variable converting the previous variable to a string. Check the data type again.
  • Next, create a third variable, converting this string variable back to a number. Check the data type one more time.
  • Compare the first and third variables using === to confirm that they are equal.
  • Compare the first and second variables or second and third variables to confirm that they are NOT equal.