0
0
Javascriptprogramming~10 mins

Primitive data types in Javascript - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Primitive data types
Start
Declare variable
Assign primitive value
Use value in code
Value stored directly
End
This flow shows how a variable is declared and assigned a primitive value, which is stored directly in memory.
Execution Sample
Javascript
let age = 25;
let name = "Alice";
let isStudent = true;
console.log(age, name, isStudent);
This code declares variables with primitive data types and prints their values.
Execution Table
StepActionVariableValue AssignedTypeOutput
1Declare and assignage25number
2Declare and assignname"Alice"string
3Declare and assignisStudenttrueboolean
4Print valuesage, name, isStudent25, "Alice", truenumber, string, boolean25 Alice true
5End
💡 All variables assigned primitive values and printed; execution ends.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
ageundefined25252525
nameundefinedundefined"Alice""Alice""Alice"
isStudentundefinedundefinedundefinedtruetrue
Key Moments - 3 Insights
Why does the variable 'age' hold the value 25 directly, not a reference?
Because 'age' is assigned a primitive number, which JavaScript stores directly in the variable, as shown in execution_table step 1.
What happens if we change 'name' after assignment?
Changing 'name' will replace the stored string value directly, without affecting other variables, since primitives are stored by value (see variable_tracker).
Why does console.log print the actual values, not memory addresses?
Primitive types hold actual values, so console.log outputs these values directly, as seen in execution_table step 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2. What type is the variable 'name' assigned?
Aboolean
Bnumber
Cstring
Dobject
💡 Hint
Check the 'Type' column in execution_table row for step 2.
At which step are all variables assigned their primitive values?
AStep 1
BStep 3
CStep 2
DStep 4
💡 Hint
Look at execution_table rows where variables get assigned values.
If we change 'isStudent' to false after step 3, what will variable_tracker show for 'isStudent' after that?
Afalse
Bundefined
Ctrue
Dnull
💡 Hint
Primitive variables hold values directly; changing them updates the stored value (see variable_tracker).
Concept Snapshot
Primitive data types in JavaScript include number, string, boolean, null, undefined, symbol, and bigint.
They store actual values directly in variables.
Assigning or copying primitives copies the value, not a reference.
Primitives are immutable; changing a variable replaces its value.
Use primitives for simple data like numbers, text, and true/false.
Full Transcript
This lesson shows how JavaScript handles primitive data types. Variables like age, name, and isStudent are declared and assigned primitive values: number, string, and boolean. Each variable stores its value directly, not a reference. When we print these variables, the actual values appear. The execution table traces each step, showing assignments and output. The variable tracker shows how values change after each step. Key moments clarify why primitives hold values directly and how changing them works. The quiz tests understanding of types, assignment steps, and value changes. Remember, primitives are simple, direct values in JavaScript.