Module 2: Variables, Data Types, Type Casting, and Comments
Lab: Variable Declaration and Types
Declare variables for different data types, use template literals for string formatting, and experiment with type conversion.
Tasks to Complete:
- Declare three variables: `studentName` (string), `studentAge` (number), and `isEnrolled` (boolean). Assign them appropriate values.
- Create a new string variable called `introduction`. Use template literals (backticks `` ` ``) to combine the values of `studentName`, `studentAge`, and `isEnrolled` into a sentence. For example: "My name is [Name], I am [Age] years old, and my enrollment status is [true/false]."
- Log the `introduction` string to the console.
- Declare a variable `numericString` and assign it a string value that represents a number (e.g., "25.5").
- Convert `numericString` to an actual number using `Number()` or `parseFloat()` and store it in a new variable `convertedNumber`. Log the type of `convertedNumber` to the console using `typeof`.
- Declare a variable `anotherNumber` and assign it any numeric value (e.g., 42).
- Convert `anotherNumber` to a string using `String()` or `.toString()` and store it in `convertedString`. Log the type of `convertedString` to the console.
JavaScript Sandbox
Output will appear here...
JavaScript execution is sandboxed. Output from `console.log()` and errors will appear above.