Type
There are 8 basic data types in React.js (Data Types, n.d.).
Type
Range
typeof Return Value
Description
NULL
null
“object”
-
An error in the language, it’s not actually an object
-
Inhabited by exactly one value: NULL
-
Represents “nothing”, “empty”, or “value unknown”
-
Indicates the absence of an object
Undefined
undefined
“undefined”
-
Inhabited by exactly one value: UNDEFINED
-
Indicates the absence of a value
-
Means “value is not assigned’
Boolean
True, false
“boolean”
-
Represents a logical entity
-
Inhabited by two values: true & false
-
Usually used for conditional operations
Number
(2^53-1) ~-(2^53-1)
“number”
-
Represents both integer and floating point numbers
-
A double-precision 64-bit binary format IEEE 754 value
-
Special numeric values : Infinity, -Infinity, NaN (Not a Number), a computational error
BigInt
Arbitrary precision
“bigint”
-
A numeric primitive that can represent integers with arbitrary magnitude
-
Can store and operate on large integers safely even beyond the safe integer limit (Number.MAX_SAFE_INTEGER) for Number
String
Effectively unlimited
“string”
-
Represents textual data
-
Encoded as a sequence of 16-bit unsigned integer values representing UTF_16 code units
Symbol
Unique identifiers
“symbol”
-
A unique and immutable primitive value
-
May be used as the key of an Object property
Object
Key-value pairs, arrays, functions
“object”
-
Non-primitive
-
Used to store collections of data ad more complex entities
(JavaScript Data Types and Data Structures - JavaScript | MDN, n.d.)
Sample React.js code (In sample application):
Variable Declaration in NULL:
1. Null (represent the absence of a value or a non-existent object)
Variable Declaration in Boolean:
1. Boolean (used for controlling the visibility of the event popup)
2. Boolean (used for checking Boolean values)
Variable Declaration in Number:
1. Number (used for holding the current month as a number)
2. Number (used for getting the number of days in the current month)
Variable Declaration in String:
1. String (used to store the text input for event descriptions)
Variable Declaration in Object:
1. Array (used to store days of the week)
2. Array (used to store event object)
3. Object (used for grouping related data, such as the hours and minutes for the event time)
4. Object (used for creating a new event object with properties such as id, date, time and text)
5. Date Object – (used to handle the current date)
6. Date Object – (used to hold a date object for the selected date)