What is a Data Type?
A data type refers to the type of data such as text, numbers, and boolean values.
1. Number
Represents numeric values like integers, floats, and natural numbers.
Example:
let age = 16; let height = 170.5;
2. String
A string represents text information. It includes letters, words, or sentences enclosed in quotes (' ', " ").
Example:
let name = 'John'; let message = 'Hello!';
3. Boolean
The Boolean data type can have one of two values: true or false, similar to a switch being toggled on or off.
Example:
let isStudent = true; let hasDriverLicense = false;
4. Object
An object is a data type used to store collections of data. For example, a student object may contain the student's name, age, and grade.
Example:
let student = { name: 'John', age: 16, grade: 'Sophomore', };
5. Array
An array is a list of values of the same type.
let fruits = ['Apple', 'Banana', 'Grapes'];
6. Other Data Types
null
null is a special value that represents 'no value'. It is used to explicitly signify that a variable has no value assigned.
Example:
let emptyValue = null;
undefined
undefined is a value assigned to variables that have been declared but not yet assigned a value. It indicates that a variable has not been defined with a value. If you declare a variable and do not initialize it, JavaScript automatically assigns it the value undefined.
Example:
let notDefinedYet; console.log(notDefinedYet); // Output: undefined
- Both
nullandundefinedsignify the absence of value, but they are used in different contexts and have different meanings.nullis used to explicitly state the absence of a value, whereasundefinedindicates that a variable has been declared but not yet assigned a value.
Lessons in this chapter Β· The Brain of the Website: What is JavaScript?
- 1. What is JavaScript?
- 2. What is a Programming Language?
- 3. How to Give Instructions to a Computer
- 4. Comment
- 5. Multiple-choice quiz
- 6. Data Types
- 7. Variable Declaration Keyword - var
- 8. Scope
- 9. Variable Declaration Keyword - let
- 10. Constants (Constant)
- 11. Operators
- 12. Variable Assignment
- 13. Identifiers and Literals
- 14. Fill-in-the-blank quiz
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help