📖 Scenario: You are learning how to store simple pieces of information in JavaScript. These simple pieces are called primitive data types. They include numbers, text, true/false values, and more.
🎯 Goal: You will create variables using different primitive data types and then display their values.
📋 What You'll Learn
Create variables with exact names and values for each primitive type
Use correct JavaScript syntax for each data type
Print the values of all variables exactly as specified
💡 Why This Matters
🌍 Real World
Primitive data types are the basic building blocks to store simple information like age, names, or true/false answers in any program.
💼 Career
Understanding primitive data types is essential for all programming jobs because they are used everywhere to hold and manipulate data.
Progress0 / 4 steps
1
Create variables with number and string types
Create a variable called age and set it to the number 25. Then create a variable called name and set it to the string "Alice".
Javascript
Hint
Use let to create variables. Numbers are written without quotes. Strings need quotes like double quotes.
2
Add boolean and undefined variables
Add a variable called isStudent and set it to the boolean value true. Also add a variable called middleName and set it to undefined.
Javascript
Hint
Boolean values are true or false without quotes. undefined means no value assigned.
3
Add null and symbol variables
Add a variable called car and set it to null. Then add a variable called id and set it to a new symbol with description "id".
Javascript
Hint
null means empty value. Symbols are unique identifiers created with Symbol().
4
Print all variable values
Use console.log to print the values of age, name, isStudent, middleName, car, and id in that order, each on its own line.
Javascript
Hint
Use console.log(variableName); to print each variable on its own line.
Practice
(1/5)
1. Which of the following is NOT a primitive data type in JavaScript?
easy
A. object
B. boolean
C. string
D. number
Solution
Step 1: Recall JavaScript primitive types
JavaScript primitive types include string, number, boolean, undefined, null, symbol, and bigint.
Step 2: Identify non-primitive types
Object is not a primitive type; it is a complex data type used to store collections.
Final Answer:
object -> Option A
Quick Check:
Primitive types exclude objects [OK]
Hint: Remember: objects are NOT primitives, others are [OK]
Common Mistakes:
Confusing object with primitive types
Thinking null is an object
Mixing symbol with object
2. Which of the following is the correct way to declare a variable with a string primitive in JavaScript?
easy
A. let name = John;
B. let name = 'John';
C. let name = "John;
D. let name = `John;
Solution
Step 1: Check string declaration syntax
Strings must be enclosed in matching quotes: single ('') or double ("") or backticks (``).
Step 2: Validate each option
let name = 'John'; uses single quotes correctly. let name = John; lacks quotes. Options C and D have unclosed quotes.
Final Answer:
let name = 'John'; -> Option B
Quick Check:
Strings need matching quotes [OK]
Hint: Strings always need matching quotes around text [OK]