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-exercises
wherever you saved it on your device. - Your VS code file explorer window should look like this:
- Then open up the
exercises.js
file in theflexpath-data-type-conversion-exercises
folder. 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 BELOW
and// 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.js
you will then use the commandnode exercises.js
in 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
typeof
to determine the type of a variable. - Handling
NaN
and 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
Date
object and its methods, liketoDateString
andtoLocaleDateString
. - 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
toFixed
and 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.