0
0
Javascriptprogramming~15 mins

Type checking using typeof in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Type Checking Using typeof in JavaScript
📖 Scenario: Imagine you are building a simple web app that needs to check the type of different values entered by users. This helps the app decide how to handle each value correctly.
🎯 Goal: You will create variables with different types of values, then use typeof to check their types and print the results.
📋 What You'll Learn
Create variables with different types: string, number, boolean, and object
Create a variable to hold the type of one of the values using typeof
Use typeof inside a loop to check types of all variables
Print the type of each variable
💡 Why This Matters
🌍 Real World
Type checking helps programs handle different kinds of data safely, like checking if a user input is a number before doing math.
💼 Career
Understanding data types and how to check them is a basic skill for any JavaScript developer, useful in debugging and writing reliable code.
Progress0 / 4 steps
1
Create variables with different types
Create four variables with these exact names and values: name with value "Alice", age with value 30, isStudent with value true, and details with value { city: "Paris" }.
Javascript
Need a hint?

Use const to create variables and assign the exact values given.

2
Create a variable to hold the type of name
Create a variable called typeOfName and set it to the type of the variable name using typeof.
Javascript
Need a hint?

Use typeof name to get the type of name.

3
Check types of all variables using a loop
Create an array called variables containing name, age, isStudent, and details. Then use a for loop with variable value to iterate over variables and create an array called types that stores the type of each value using typeof.
Javascript
Need a hint?

Put the variables in an array, then loop over it and use typeof on each item.

4
Print the types of all variables
Use console.log to print the types array.
Javascript
Need a hint?

Use console.log(types) to show the array of types.