Data Types
Understanding Primitive Types
3 min readAug 27, 2023
Field notes while going through the JavaScript Roadmap
What are Data Types?
- Every variable in JavaScript has a data type which is used to describe the operations possible on that value
- There are 7 primitive data types:
Number
,BigInt
,String
,Boolean
,Null
,Undefined
andSymbol
- The
Object
data type is not considered a primitive — and will be covered in a separate post
String
A string is a sequence of textual characters
Each character in a string has a given position, formally known as an index. To access a character in a string, we specify its index as an integer (starting from 0)
let lang = "JavaScript";
let firstLetter = lang[0];
console.log(firstLetter); // Output: "J"
Number
A Number
is an integer or whole number without a decimal point
let value = 123;
A float or floating-point number is a Number
with a decimal point
let value = -1.23;
Boolean
A Boolean
is logical data type that can only return a true
or false
value
let isAdmin = true;