Data can come in all shapes and sizes. We use the term data type to specify the type of a specific value.
In our everyday language use, we differentiate between letters and numbers and usually, we will use them for different purposes. In programming, it is no different. We call the most basic data types primitives.
The main features of a primitive data type are:
It is not an object (a collection of keys and values)
It does not have its own methods (property of an object which is a function)
It is immutable (it cannot be changed and is read-only).
- BigInt Let's briefly take a look at each of these types!
50 //Whole number 1 //Positive number -1 //Negative number 0.1 //Decimal
One of two values true or false (Not wrapped in quotes). A bit like saying yes or no.
The string data type refers to any set of characters wrapped inside single or double-quotes. The following would both be examples of strings:
"I am a string"; 'I am a string';
Represents nothing or a nonvalue but often this is intentionally set. You could create a variable and intentionally set the value of the variable to null. For example:
let myEmptyVariable = null;
Undefined also represents no value. As opposed to null, variables that are defined with no value or variables which have not been declared (created at all) will be given the value of undefined.
let a; console.log(a); // ---> Returns undefined
Undefined is often given to us in the form of an error. Functions will return undefined if no return value is set.
const firstSymbol = Symbol(); const secondSymbol = Symbol(); console.log(firstSymbol === secondSymbol); // ---> Returns false
Useful for representing large numerical values, Specifically those over 15 digits long. You can create this by placing n at the end of a literal number. It can also be created by using the BigInt constructor and passing the value into the parameters.
const ourInteger = 1118998854361892n; const ourSecondInteger = BigInt(1118998854361892); console.log(ourSecondInteger); // ---> Returns 1118998854361892n
Please feel free to post any comments, questions or feedback!