The intention of this exercise is to give you more experience working with JavaScript's data types and converting values from one type to another.
- Using Visual Studio Code, open the folder
flexpath-data-type-conversion-exerciseswherever you saved it on your device. - Your VS code file explorer window should look like this:

- Then open up the
exercises.jsfile in theflexpath-data-type-conversion-exercisesfolder. Inside of this file we have provided exercises for you to complete, written in code comments. For each exercise, please code ONLY in the space between the comments// CODE IN THE OPEN LINES BELOWand// CODE IN THE OPEN LINES ABOVE - To run your code for different exercises, you will update the exercise mentioned
on line 20 of the file.

- After changing that line, make sure to SAVE the file before running it.
- To run your code in exercises.js, you will update line 20 to run the exercise code you want to run and save the file. THEN, open a Terminal window in VS Code by going to your toolbar at the top of the page and selecting "Terminal" -> "New Terminal"
- Inside of this terminal, check that you have Node.js installed by running the
command
node -v. If your computer doesn't recognize that keyword, please go back and ensure you installed Node.js correctly. - To run
exercises.jsyou will then use the commandnode exercises.jsin the terminal to run the file.
We have included a screen recording showing this process in the file
run-exercise-2-recording.mp4 in this repo.
VIDEO DISCLAIMER - You will need to clone the repo to your local device before you can watch the .mp4 file since GitHub does not support watching it from here.
Exercise solutions are in the /solution folder
-
Data Types:
- Primitive data types such as strings, numbers, booleans, null, and undefined.
- Objects and arrays as non-primitive data types.
- Differences between primitive and reference types.
-
Type Conversion:
- Converting between different data types (e.g., strings to numbers, numbers to booleans).
- Using
typeofto determine the type of a variable. - Handling
NaNand checking for it usingisNaN.
-
String Manipulation:
- Using template literals for string interpolation.
- Common string methods like
toUpperCase,toLowerCase,indexOf, andincludes.
-
Date and Time:
- Working with the
Dateobject and its methods, liketoDateStringandtoLocaleDateString. - Formatting dates and times for different locales using
Intl.DateTimeFormat.
- Working with the
-
Number Formatting:
- Using methods like
Math.round,Math.ceil, andMath.floor. - Formatting numbers with
toFixedand for different locales withIntl.NumberFormat.
- Using methods like
-
JSON:
- Converting objects to JSON strings using
JSON.stringify. - Parsing JSON strings back to objects using
JSON.parse. - Handling JSON parsing errors.
- Converting objects to JSON strings using
-
Boolean Logic:
- Truthy and falsy values.
- Converting values to booleans and understanding boolean contexts.
-
Locale and Internationalization (i18n):
- Using locale codes to format numbers, dates, and currency.
- The concept of locales and how it affects string and number formatting.