Learning Goals
- Create variables with
let. - Update variable values.
- Use
typeofto check a data type. - Explain in plain words what each variable stores.
JavaScript Foundations
Now we store real values in variables and print them clearly.
let.typeof to check a data type.When we write this, we mean each variable stores one piece of information.
// Save as lesson2.js
let internName = "Patricia";
let week = 1;
let isPresent = true;
week = week + 1;
console.log(internName);
console.log(week);
console.log(isPresent);
console.log(typeof internName);
console.log(typeof week);
When we write this, we mean:
internName stores text, so its type is string.week stores a number, so its type is number.isPresent stores true/false, so its type is boolean.week = week + 1; means: take current value and add one.let for now in this track.node lesson2.js in your terminal.Imagine you are tracking one intern's week details.
let intern = "Asha";
let daysPresent = 4;
let submittedTask = false;
console.log(intern);
console.log(daysPresent);
console.log(submittedTask);
That code means: we are storing a person's name, attendance count, and task status.
Variables are how your program remembers information. In real projects, this is everything: user names, scores, prices, login status, dates, and many more values. If you do not store values properly, you cannot make decisions, calculate results, or show useful output. That is why this lesson is foundational.
Notice that we also check data type with typeof. This is a beginner superpower. If your app behaves strangely, checking type often reveals the problem quickly. For example, adding text and adding numbers are different operations. Seeing the type helps you debug with confidence instead of guessing.
"2" is not the same as 2.true and false are not in quotes.isMorning.typeof.Build a file called profile.js with 6 variables: name, age, city, course, isOnline, and week. Update one value, then print all values and their types.
let name = "Brian";
let age = 20;
let city = "Jinja";
let course = "JavaScript Basics";
let isOnline = true;
let week = 1;
week = week + 1;
console.log(name, typeof name);
console.log(age, typeof age);
console.log(city, typeof city);
console.log(course, typeof course);
console.log(isOnline, typeof isOnline);
console.log(week, typeof week);