What are Data Types?
Data types refer to the type
of data such as characters, numbers, and true/false values.
Programming languages provide various data types to process and store data.
In JavaScript, the following data types are used:
Number
This represents numeric values such as integers, floats, and natural numbers.
let age = 16; let height = 170.5;
String
Strings represent textual information. Any letter, word, or sentence enclosed in quotes (' ', " ") is considered a string.
let name = 'John'; let message = 'Hello there!';
Boolean
The Boolean data type can only have one of two values: true
or false
, similar to turning a switch on or off.
let isStudent = true; let hasDriverLicense = false;
Object
An object is a data type used to store multiple values or complex entities. For instance, a student object can hold information like name, age, and grade.
let student = { name: 'John', age: 16, grade: '11th Grade', };
Array
An array lists data of the same type, as shown below.
let fruits = ['Apple', 'Banana', 'Grape'];
null
null
is a special value that represents 'no value'.
You assign null
to a variable when you want to explicitly indicate that it does not have any value yet.
let emptyValue = null;
undefined
undefined
indicates that a variable has been declared but has not yet been assigned a value.
It means the value is not defined.
If you declare a variable and do not initialize it, JavaScript automatically assigns it the value of undefined
.
let notDefinedYet; console.log(notDefinedYet); // Output: undefined
While both null
and undefined
represent the concept of a lack of value, they are used in different contexts and have distinct meanings.
null
is used when you explicitly want to express the absence of any value, whereas undefined
signifies the initial state of a variable or a situation where no value has been passed where one is expected.
Which of the following data types represents a true/false
value?
Number
String
Boolean
Object
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help
Code Editor
Execution Result