Lesson goal: Recognise five common kinds of JavaScript values.
A data type describes the kind of value you are working with.
A student’s name is text. Their marks are numbers. Whether they have completed a lesson is a true-or-false value.
A string stores text.
const studentName = "Aman Singh";
const courseName = 'JavaScript Basics';
console.log(studentName);
console.log(courseName);
Numbers inside quotation marks are also strings:
const studentCode = "101";
A phone number or an identification code is often best treated as text because you do not normally perform arithmetic on it.
const notebookPrice = 60;
const penPrice = 12.5;
const temperature = -3;
number type.Do not include currency symbols inside numeric values:
const price = 60;
"₹60", you have created a string, not a number suitable for direct arithmetic.true or falseA boolean has one of two values:
const isEnrolled = true;
const hasCompletedCourse = false;
console.log(isEnrolled);
console.log(hasCompletedCourse);
true
false
const firstValue = false;
const secondValue = "false";
firstValue is a boolean. secondValue is text.
undefined: No value assigned yetlet examScore;
console.log(examScore);
undefined
examScore, but we have not assigned a value.Later, we can update it:
examScore = 85;
console.log(examScore);
null: An intentional empty valueconst selectedCourse = null;
console.log(selectedCourse);
null means we intentionally represent “no course selected.”| Value | Typical meaning |
|---|---|
undefined |
A value has not been provided or assigned |
null |
The program intentionally represents an empty or absent value |
0 |
A numeric value of zero |
"" |
A string with no characters |
These values are different. For example, a score of 0 means the student received zero marks. An undefined score may mean the marks have not been entered.
let result = 80;
console.log(result);
result = "Not checked";
console.log(result);
Identify the type of each value:
"Punjab"
75
true
null
undefined
"75"
Lesson recap
Strings hold text, numbers support calculations, and booleans represent true or false. Use null for an intentional absence; a declared variable without an assigned value starts as undefined.